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 ...
随机推荐
- Redis 高可用及分片集群,说了你也不懂
Redis 简介 Memcached: 优点:高性能读写.单一数据类型.支持客户端式分布式集群.一致性hash 多核结构.多线程读写性能高. 缺点:无持久化.节点故障可能出现缓存穿透.分布式需要客户端 ...
- stl_hash_set.h
stl_hash_set.h // Filename: stl_hash_set.h // Comment By: 凝霜 // E-mail: mdl2009@vip.qq.com // Blog: ...
- Tomcat 优化方案 和 配置详解
转载: http://blog.csdn.net/yi2672379417/article/details/51442229
- NET持续集成与自动化部署
https://www.cnblogs.com/hunternet/p/9590287.html 相信每一位程序员都经历过深夜加班上线的痛苦!而作为一个加班上线如家常便饭的码农,更是深感其痛.由于我们 ...
- 蓝桥杯 算法训练 ALGO-146 4-2找公倍数
算法训练 4-2找公倍数 时间限制:1.0s 内存限制:256.0MB 查看参考代码 问题描述 这里写问题描述. 打印出1-1000所有11和17的公倍数. 样例输入 一个满足题 ...
- Jetty + Servlet 实现文件下载
Jetty非常适合做嵌入式web开发,正如Jetty的口号"Don’t deploy your application in Jetty, deploy Jetty in your appl ...
- Django基础(二)—— models
六:Models示例 Django本身提供了非常强大易使用的ORM组件,并且支持多种数据库. 配置连接数据文件 在自己创建的project 目录下编辑settings.py DATABASES = { ...
- SQL修改日期时间型数据中的年月日
以下语句为更改 tevent表中的eventtime字段为2011-7-16当eventtime为2012-02-29时 update tevent set eventtime='2011-7-16 ...
- Rename Oracle Managed File (OMF) datafiles in ASM(ZT)
Recently I was asked to rename a tablespace. The environment was Oracle version 11.2.0.3 (both datab ...
- leetcode230
/** * Definition for a binary tree node. * public class TreeNode { * public int val; * public TreeNo ...