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 ...
随机推荐
- 面试题41:和为s的两个数字VS和为s的连续正数序列
题目一:输入一个递增排序的数组和一个数字s,在数组中查找两个数,使得它们的和正好是s.如果有多对数字的和为s,输出任意一对即可. vector<int> findNumberwWithSu ...
- 在Java中定义常量
方法一采用接口(Interface)的中变量默认为static final的特性. 方法二采用了Java 5.0中引入的Enum类型. 方法三采用了在普通类中使用static final修饰变量的方法 ...
- 初识Linux--虚拟机下安装Ubuntu16
最近接收到任务,说是下半年可能要搞全文检索.听到后顿时炸锅了,一方面是对新技术的兴奋,另一方面,我TM连Linux都不会玩,怎么搞全文检索.怀揣着对开源世界的无线向往(恐惧),我决定试水Linux. ...
- Ubuntu 16.10 Apache PHP Server
/******************************************************************************************* * Ubunt ...
- POJ - 3150 :Cellular Automaton(特殊的矩阵,降维优化)
A cellular automaton is a collection of cells on a grid of specified shape that evolves through a nu ...
- 1151 LCA in a Binary Tree(30 分)
The lowest common ancestor (LCA) of two nodes U and V in a tree is the deepest node that has both U ...
- 洛谷 P2290 [HNOI2004]树的计数
题目描述 输入输出格式 输入格式: 输入文件第一行是一个正整数n,表示树有n个结点.第二行有n个数,第i个数表示di,即树的第i个结点的度数.其中1<=n<=150,输入数据保证满足条件的 ...
- Unity Shader实现描边效果
http://gad.qq.com/article/detail/28346 描边效果是游戏里面非常常用的一种效果,一般是为了凸显游戏中的某个对象,会给对象增加一个描边效果.本篇文章和大家介绍下利用S ...
- resize2fs: Bad magic number in super-block while trying to open /dev/centos/root Couldn't find valid filesystem superblock
今天在进行lvm扩容之后,按照惯例进行 resize2fs 操作,发现报如下错误: # resize2fs /dev/centos/root resize2fs 1.42.9 (28-Dec-2013 ...
- 使用PowerShell在Azure China创建Data Warehouse
微软的Azure Data Warehouse是基于MPP架构的分布式系统: Control Node负责管理系统和接受用户的请求,Compute Node负责计算. 目前在国内Azure Data ...