码迷,mamicode.com
首页 > 其他好文 > 详细

codeforces-1027 C Minimum Value Rectangle

时间:2018-08-21 13:09:59      阅读:181      评论:0      收藏:0      [点我收藏+]

标签:style   i+1   algorithm   ace   sort   back   code   codeforce   int   

 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 }

 

codeforces-1027 C Minimum Value Rectangle

标签:style   i+1   algorithm   ace   sort   back   code   codeforce   int   

原文地址:https://www.cnblogs.com/Asurudo/p/9510673.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!