1027C Minimum Value Rectangle
题目大意
有n个木棍,让你选4根使得组成的矩形的周长的平方除以面积最小。
分析
这个题看起来就是一个需要证明的贪心,下面我们来证明一下:
所以我们只需要枚举一边所有的a的可能值,然后b就是比a大的边中最小的,复杂度O(n)。总复杂度O(nlogn)。
代码
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<ctime>
#include<vector>
#include<set>
#include<map>
#include<stack>
using namespace std;
const double inf = ;
long long a[],b[],cnt;
inline void work(){
long long n,m,i,j,k;
cnt=;
scanf("%lld",&n);
for(i=;i<=n;i++)
scanf("%lld",&a[i]);
sort(a+,a+n+);
long long sum=;
for(i=;i<=n;i++)
if(!sum)sum++;
else if(sum==){
if(a[i]==a[i-]){
b[++cnt]=a[i];
sum=;
}
}
double ans=inf;
long long x,y;
for(i=;i<cnt;i++)
if(ans>double(b[i+])/b[i]+double(b[i])/b[i+]){
ans=double(b[i+])/b[i]+double(b[i])/b[i+];
x=b[i],y=b[i+];
}
cout<<x<<' '<<x<<' '<<y<<' '<<y<<endl;
}
int main(){
long long n,m,i,j,k,t;
scanf("%lld",&t);
while(t--){
work();
}
return ;
}
1027C Minimum Value Rectangle的更多相关文章
- [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 ...
- CF1027C Minimum Value Rectangle 贪心 数学
Minimum Value Rectangle time limit per test 2 seconds memory limit per test 256 megabytes input stan ...
- 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 ...
- 【leetcode】963. Minimum Area Rectangle II
题目如下: Given a set of points in the xy-plane, determine the minimum area of any rectangle formed from ...
- 963. Minimum Area Rectangle II
Given a set of points in the xy-plane, determine the minimum area of any rectangle formed from these ...
- 【LeetCode】963. Minimum Area Rectangle II 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 线段长+线段中心+字典 日期 题目地址:https: ...
- [Swift]LeetCode939. 最小面积矩形 | Minimum Area Rectangle
Given a set of points in the xy-plane, determine the minimum area of a rectangle formed from these p ...
- LeetCode - Minimum Area Rectangle
Given a set of points in the xy-plane, determine the minimum area of a rectangle formed from these p ...
- 【leetcode】939. Minimum Area Rectangle
题目如下: Given a set of points in the xy-plane, determine the minimum area of a rectangle formed from t ...
随机推荐
- 完成一个servlet 就要在web.xml里面配一个映射,这样就有一个路径供我们 使用????? servlet从页面接收值?
最后,最容易忘记的是:在dao层中 调用xml里的删除sql语句 后面需要人为加上事务提交.一定要! sqlSession.commit();//jdbc是自动提交,但是mybatis中不是自动提交的 ...
- BEC listen and translation exercise 6
能听懂自己的录音,说明发音还行,可惜听不懂... Another problem is that the members of the Biramichi fishing cooperative ar ...
- 关于 freetds pymssql 的安装部署
关于 freetds pymssql 的安装部署一.安装: (freetds-0.91 pymssql 2.0.1) 如果要在linux机器 连mysqlsever 1.需要安装freetds./co ...
- THUSC 2017 大魔法师
一个序列,每个物品有三个权值 $A,B,C$ 要求维护: 1.区间 $A_i+=B_i$ 2.区间 $B_i+=C_i$ 3.区间 $C_i+=A_i$ 4.区间 $A_i+=v$ 5.区间 $B_i ...
- gulp之文件合并以及整合html中的script和link
gulp的文件合并,也就是将多个js或css文件合并为一个的插件是:gulp-concat gulp将html中的多个<script>或<link>合并为一个的插件是:gulp ...
- iOS播放视频
1.首先导入 MediaPlayer import MediaPlayer 2.播放事件 class ViewController:UIViewController{ var pc:MPMoviePl ...
- HDU4825(字典树+贪心)
Xor Sum Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 132768/132768 K (Java/Others)Total S ...
- Oracle 数据库迁移到MySQL (kettle,navicate,sql developer等工具
Oracle 数据库迁移到MySQL (kettle,navicate,sql developer等工具 1 kettle --第一次使用kettle玩迁移,有什么不足之处和建议,请大家指正和建议. ...
- vmware全屏后去掉上面的横杠
全屏后选择查看—>独占模式最上面的杠就没了,而且不按退出快捷键,不会在切换到外面的系统中了.
- pycharm中 unittests in xxxx 运行模式
pycham中 当你运行时 ,使用的 是 Run "unittests in xxxx" 模式时候,if __name__ == '__main__': 后面的代码是不执行的 ...