codeforces-1027 C Minimum Value Rectangle
1 #include <iostream> 2 #include <unordered_map> 3 #include <algorithm> 4 #include <vector> 5 #include <queue> 6 #define DEF 0x3f3f3f3f 7 using namespace std; 8 9 int main() 10 { 11 int T; 12 scanf("%d",&T); 13 while(T --) 14 { 15 int n; 16 int hash[10001] {0}; 17 vector<int> deal; 18 double diff = 10001; 19 int edge1 = 0,edge2 = 0; 20 int flag = 0; 21 22 scanf("%d\n",&n); 23 while(n --) 24 { 25 int tmp; 26 scanf("%d",&tmp); 27 hash[tmp] ++; 28 if(hash[tmp]==2) 29 deal.emplace_back(tmp); 30 if(hash[tmp]==4) 31 { 32 flag = 1; 33 edge1 = edge2 = tmp; 34 } 35 } 36 37 if(flag) 38 { 39 printf("%d %d %d %d\n",edge1,edge1,edge2,edge2); 40 continue; 41 } 42 sort(deal.begin(),deal.end()); 43 double minidiff = DEF; 44 for(int i = 0; i < deal.size()-1; i ++) 45 { 46 double tmp_diff = (double)deal[i+1]/(double)deal[i] + (double)deal[i]/(double)deal[i+1]; 47 // cout << deal[i+1] << " " << deal[i] << " " << tmp_diff << endl; 48 if(tmp_diff<diff) 49 { 50 edge1 = deal[i]; 51 edge2 = deal[i+1]; 52 diff = tmp_diff; 53 } 54 } 55 printf("%d %d %d %d\n",edge1,edge1,edge2,edge2); 56 } 57 return 0; 58 }