Round#579(Div 3) B. Equal Rectangles

The meaning of problems: inputting a set of long sides of the rectangle, rectangular area of ​​the same inquiry whether a set of configuration

Thinking: check whether these sides can form a rectangle, i.e., the number of sides of the same length is an even number check

   Then the number of edges divided by two, are sorted;

   Each time the longest side removed without replacement and ordered from multiplying the shortest side edges, it is checked whether they are equal.

 1 #include <iostream>
 2 #include <vector>
 3 #include <map>
 4 #include <algorithm>
 5 using namespace std;
 6 int main(){
 7     int t;
 8     cin>>t;
 9     while(t --){
10         map<int, int> cnt;
11         vector<int> note;
12         int n;
13         cin>>n;
14         n *= 4;
15         for(int i = 0; i < n; i ++){
16             int inp;
17             cin>>inp;
18             cnt[inp] ++;
19             note.push_back(inp);
20         }
21         bool f = true;
22         for(map<int, int>::iterator it = cnt.begin();\
23                 it != cnt.end(); \
24                 it ++){
25             if(it->second & 1){
26                 f = false;
27                 break;
28             }
29             for(int i = it->second; i; i -= 2)
30                 note.push_back(it->first);
31         }
32         if(f == false)
33             cout<<"NO"<<endl;
34         else{
35             int len = note.size();
36             bool flag = true;
37             sort(note.begin(), note.end());
38             int tmp = note[0]*note[len - 1];
39             for(int i = 0; i < len / 2; i ++){
40                 if(note[i]*note[len - 1 - i] != tmp){
41                     flag = false;
42                     break;
43                 }
44             }
45             if(flag)
46                 cout<<"YES"<<endl;
47             else
48                 cout<<"NO"<<endl;
49         }
50     }
51     return 0;
52 }

 

Guess you like

Origin www.cnblogs.com/quantumbird/p/11349595.html