传送门

题目大意

有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. commons-dbcp连接池的使用

    数据库连接池 池参数(所有池参数都有默认值): 初始大小: 最小空闲连接数: 增量:一次创建的最小单位(5个) 最大空闲连接数:12个 最大连接数:20个 最大的等待时间:1000毫秒 四大连接参数: ...

  2. 《深入理解 C# 第2版》 - 书摘精要

    (P13) 在很大程度上,C# 2 更像是对 C# 1 的各种不足之处的修修补补,所以并没有一鸣惊人.而 C# 3 中几乎所有特性都是为了构建 LINQ,并且其结果也十分特别: (P24) 为了让委托 ...

  3. 是因为Session只能让服务器在一次连续的会话中记住你,而Cookie是记住浏览器一段时间

    Cookie的作用 因为http协议先天不足是无记忆性. 还有一个区别是:Session是服务器端保存会话状态的机制. 而Cookie则是浏览器端保存会话的机制. Cookie 的应用

  4. L118

    The company needs to focus on its biggest clients.This article discussed the events that led to her ...

  5. scrapy入门实践1

    Scrapy是一个为了爬取网站数据,提取结构性数据而编写的应用框架. 可以应用在包括数据挖掘,信息处理或存储历史数据等一系列的程序中. 这就是整个Scrapy的架构图了: 各部件职能: Scrapy ...

  6. zabbix监控进程

    参考http://chenx1242.blog.51cto.com/10430133/1837990 1 前期说明 zabbix_server查看“文件在后台运行数量”所对应的key就是:proc.n ...

  7. “makefile”写法详解,一步一步写一个实用的makefile,详解 sed 's,$∗\.o[ :]*,\1.o $@ : ,g' < $@.

    目的:编写一个实用的makefile,能自动编译当前目录下所有.c/.cpp源文件,支持二者混合编译.并且当某个.c/.cpp..h或依赖的源文件被修改后,仅重编涉及到的源文件,未涉及的不编译. 二要 ...

  8. 把ASM下的HDD VM转换成ARM下Managed Disk的SSD VM

    在ASM下,要把HDD的VM转换成SSD的VM步骤非常复杂.需要手工把Disk从普通存储账户复制到高级存储账户.再通过这个Disk创建VM. 目前在有了ASM到ARM的迁移工具,以及Managed D ...

  9. 转:三思!大规模MySQL运维陷阱之基于MyCat的伪分布式架构

    在微信公众号看到一篇关于mycat的文章,觉得分析的很不错,给大家分享一下 三思!大规模MySQL运维陷阱之基于MyCat的伪分布式架构 原文链接:https://mp.weixin.qq.com/s ...

  10. 关于python+django操作数据库中的表

    数据库中的表示这样设计的 class C(models.Model): name = models.CharField(max_length=32) class B(models.Model): na ...