传送门

题目大意

有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的更多相关文章

  1. [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 ...

  2. CF1027C Minimum Value Rectangle 贪心 数学

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

  3. 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 ...

  4. 【leetcode】963. Minimum Area Rectangle II

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

  5. 963. Minimum Area Rectangle II

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

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

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

  7. [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 ...

  8. LeetCode - Minimum Area Rectangle

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

  9. 【leetcode】939. Minimum Area Rectangle

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

随机推荐

  1. shell编程-条件判断与流程控制

    1.条件判断式 按照文件类型进行判断: 两种判断格式: test -e /root/install.log [ -e /root/install.log ] 判断命令是否正确执行: [ -d /roo ...

  2. ICE的Glacier2使用

    1.使用Glacier2的步骤:   A.编写一个Glacier2的配置文件,参见样例   B.设置Glacier2的访问鉴权(密码或者证书),passwords文件每行样例"test xx ...

  3. js改变select的选中项不触发select的change事件

    // test var selectEl = document.querySelector('select') var buttonEl = document.querySelector('butto ...

  4. centos6下搭建gitlab

    gitlab安装方法,最新安装方法见官网:https://www.gitlab.com.cn/installation/#centos-6 1.在 Centos 6 系统上, 下面的命令将在系统防火墙 ...

  5. POJ - 2891 Strange Way to Express Integers (扩展中国剩余定理)

    题目链接 扩展CRT模板题,原理及证明见传送门(引用) #include<cstdio> #include<algorithm> using namespace std; ty ...

  6. HDU - 5412 CRB and Queries (整体二分)

    题目链接 动态区间第k小,但是这道题的话用主席树+树状数组套线段树的空间复杂度是O(nlog2n)会爆掉. 另一种替代的方法是用树状数组套平衡树,空间复杂度降到了O(nlogn),但我感觉平衡树是个挺 ...

  7. 如何打开 Windows 的热键提示

    如何打开 Windows 的热键提示 很早之前我记的 Windows 是有热键提示的,不知道什么时候开始默认不显示了,难道 微软是为是美观? 找了一下原来是有地方可以设置的.

  8. linux下查找命令两则

    由于本人不会阅读man手册,因此需要几下两个常用的查找命令: (1)在某个目录及其子目录查找某个文件并打印完整路径: find ./ -name "assertions.h" -e ...

  9. Visualforce入门第六篇_2017.3.1

    Visualforce实现过滤.数据列表显示.分页功能 可以参考salesforce官网开发文档:https://trailhead.salesforce.com/modules/visualforc ...

  10. flask之全局对象

    from flask import current_app, g g is a special object that is unique for each request. It is used t ...