codeforces-1027 C Minimum Value Rectangle
Posted asurudo
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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); 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 ",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 ",edge1,edge1,edge2,edge2); 56 } 57 return 0; 58 }
以上是关于codeforces-1027 C Minimum Value Rectangle的主要内容,如果未能解决你的问题,请参考以下文章
Codeforces 1027F. Session in BSU
codeforces 1027E. Inverse Coloring(计数)
Session in BSU CodeForces - 1027F(思维 树 基环树 离散化)