https://www.luogu.org/problemnew/show/CF1027C

  1. #include<cstdio>
  2. #include<string>
  3. #include<cstdlib>
  4. #include<cmath>
  5. #include<iostream>
  6. #include<cstring>
  7. #include<set>
  8. #include<queue>
  9. #include<algorithm>
  10. #include<vector>
  11. #include<map>
  12. #include<cctype>
  13. #include<stack>
  14. #include<sstream>
  15. #include<list>
  16. #include<assert.h>
  17. #include<bitset>
  18. #include<numeric>
  19. #define debug() puts("++++")
  20. #define gcd(a,b) __gcd(a,b)
  21. #define lson l,m,rt<<1
  22. #define rson m+1,r,rt<<1|1
  23. #define fi first
  24. #define se second
  25. #define pb push_back
  26. #define sqr(x) ((x)*(x))
  27. #define ms(a,b) memset(a,b,sizeof(a))
  28. #define sz size()
  29. #define be begin()
  30. #define pu push_up
  31. #define pd push_down
  32. #define cl clear()
  33. #define lowbit(x) -x&x
  34. #define all 1,n,1
  35. #define mod(x) ((x)%M)
  36. #define pi acos(-1.0)
  37. #define rep(i,x,n) for(int i=(x); i<(n); i++)
  38. using namespace std;
  39. typedef long long LL;
  40. typedef unsigned long long ULL;
  41. typedef pair<int,int> P;
  42. const int INF = 0x3f3f3f3f;
  43. const int maxn = 1e4+10; //1e5不行!
  44. const double eps = 1e-8;
  45. const int dx[] = {-1,1,0,0,1,1,-1,-1};
  46. const int dy[] = {0,0,1,-1,1,-1,1,-1};
  47. int dir[2]={-1,1};
  48. const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  49. const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  50. int t,n;
  51. int vis[maxn];
  52. int b[maxn];
  53. int x;
  54. inline int read() //要读入挂!
  55. {
  56. char x;
  57. while((x = getchar())<'0' || x>'9');
  58. int u = x-'0';
  59. while((x = getchar())>='0' && x<='9') u = (u<<3)+(u<<1)+x-'0';
  60. return u;
  61. }
  62. /*
  63. 1345 4409 1345 4409 8664 8664
  64. 4409 4409 8664 8664=4225(v)
  65. 1345 1345 4409 4409=3064(x)
  66. */
  67. int main()
  68. {
  69. t=read();
  70. while(t--)
  71. {
  72. int f=1;
  73. ms(vis,0);
  74. ms(b,0);
  75. n=read();
  76. int m=0;
  77. for(int i=0;i<n;i++)
  78. {
  79. x=read();
  80. vis[x]++;
  81. if(vis[x]==4 && f)
  82. {
  83. printf("%d %d %d %d\n",x,x,x,x);
  84. f=0;
  85. }
  86. if(vis[x]==2 && f)
  87. b[m++]=x;
  88. }
  89. if(f)
  90. {
  91. sort(b,b+m);
  92. int l,r;
  93. double Min=INF;
  94. for(int i=0;i<m-1;i++)
  95. {
  96. double tmp = (double)b[i]/b[i+1]+(double)b[i+1]/b[i];
  97. if(tmp<Min)
  98. {
  99. Min = tmp;
  100. l=b[i];
  101. r=b[i+1];
  102. }
  103. }
  104. printf("%d %d %d %d\n",l,l,r,r);
  105. }
  106. }
  107. return 0;
  108. }
  109. /*
  110. 【题意】
  111. 3
  112. 4
  113. 7 2 2 7
  114. 8
  115. 2 8 1 4 8 2 1 5
  116. 5
  117. 5 5 5 5 5
  118. 【类型】
  119. 【分析】
  120. 【时间复杂度&&优化】
  121. 【trick】
  122. 【数据】
  123. */

CF1027C Minimum Value Rectangle【贪心/公式化简】的更多相关文章

  1. CF1027C Minimum Value Rectangle 贪心 数学

    Minimum Value Rectangle time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

  2. CF1027C Minimum Value Rectangle

    之前做的时候没想出来...现在来数学推导一波. 题意:从n个木棒中选出4个拼成一个矩形,使得 (周长)2/面积 最小. 解:设矩形宽a长b.我们要最小化下面这个式子: 去掉常数,不妨设b = a + ...

  3. [Swift]LeetCode963. 最小面积矩形 II | Minimum Area Rectangle II

    Given a set of points in the xy-plane, determine the minimum area of any rectangle formed from these ...

  4. LC 963. Minimum Area Rectangle II

    Given a set of points in the xy-plane, determine the minimum area of any rectangle formed from these ...

  5. 【leetcode】963. Minimum Area Rectangle II

    题目如下: Given a set of points in the xy-plane, determine the minimum area of any rectangle formed from ...

  6. [zoj3813]Alternating Sum 公式化简,线段树

    题意:给一个长度不超过100000的原串S(只包含数字0-9),令T为将S重复若干次首尾连接后得到的新串,有两种操作:(1)修改原串S某个位置的值(2)给定L,R,询问T中L<=i<=j& ...

  7. 963. Minimum Area Rectangle II

    Given a set of points in the xy-plane, determine the minimum area of any rectangle formed from these ...

  8. 【LeetCode】963. Minimum Area Rectangle II 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 线段长+线段中心+字典 日期 题目地址:https: ...

  9. 【CF1027C】Minimum Value Rectangle(贪心,数学)

    题意:给定n根木棍,不允许拼接或折断,选择四根组成矩形,求所有合法矩形中周长平方与面积比最小的一个,输出拼成这个矩形的四根木棍 n<=1e6 思路:猜结论:答案必定从相邻的4根中产生 证明见ht ...

随机推荐

  1. cssText基本使用及注意事项

    一.cssText之起步 那些年,我们是这样设置样式的: xxx.style.width = "233px"; xxx.style.position = "fixed&q ...

  2. 耗子学Python了(2)__Python开发“Hello World”

    一:开发工具 在网上看到的用的开发工具Aptana Studio,我下载的是Aptana_Studio_3_Setup_3.6.1.exe,在安装的过程中啊,出现了各种问题,然后安装后了也出现打不开的 ...

  3. J2EE保留小数问题

    如果在前台页面,可以直接使用js的toFixed() 方法.number.toFixed(x)  可把 Number 四舍五入为指定小数位数的数字.参数x :必需.规定小数的位数,是 0 ~ 20 之 ...

  4. 【NOIP】提高组2012 国王游戏

    [题意] 恰逢H国国庆,国王邀请n位大臣来玩一个有奖游戏.首先,他让每个大臣在左.右 手上面分别写下一个整数,国王自己也在左.右手上各写一个整数.然后,让这n位大臣排 成一排,国王站在队伍的最前面.排 ...

  5. Spring理论基础-面向切面编程

    AOP是Aspect-Oriented Programming的缩写,中文翻译是面向切面编程.作为Spring的特征之一,是要好好学习的. 首先面向切面编程这个名称很容易让人想起面向对象编程(OOP) ...

  6. js刷新页面方法 -- (转)

    1,reload 方法,该方法强迫浏览器刷新当前页面. 语法:location.reload([bForceGet])   参数: bForceGet, 可选参数, 默认为 false,从客户端缓存里 ...

  7. Bitmap算法应用实例(转)

    关于数据库查询工作,例如有如下数据库表 要想统计所有90后的程序员该怎么做呢?用一条求交集的SQL语句即可: Select count(distinct Name) as 用户数 from table ...

  8. 一个简单爬免费代理IP的脚本

  9. 简谈const限定符

    const修饰的数据类型是常量类型,常量类型的对象和变量在定义初始化后是不能被更新的.其实只用记住这一个概念,就可以明白const操作对象的方法. 1)定义const常量 最简单的: const in ...

  10. BP神经网络-- 基本模型

    转载:http://www.cnblogs.com/jzhlin/archive/2012/07/28/bp.html BP 神经网络中的 BP 为 Back  Propagation 的简写,最早它 ...