CF1027C Minimum Value Rectangle【贪心/公式化简】
https://www.luogu.org/problemnew/show/CF1027C
#include<cstdio>
#include<string>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<cstring>
#include<set>
#include<queue>
#include<algorithm>
#include<vector>
#include<map>
#include<cctype>
#include<stack>
#include<sstream>
#include<list>
#include<assert.h>
#include<bitset>
#include<numeric>
#define debug() puts("++++")
#define gcd(a,b) __gcd(a,b)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define fi first
#define se second
#define pb push_back
#define sqr(x) ((x)*(x))
#define ms(a,b) memset(a,b,sizeof(a))
#define sz size()
#define be begin()
#define pu push_up
#define pd push_down
#define cl clear()
#define lowbit(x) -x&x
#define all 1,n,1
#define mod(x) ((x)%M)
#define pi acos(-1.0)
#define rep(i,x,n) for(int i=(x); i<(n); i++)
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> P;
const int INF = 0x3f3f3f3f;
const int maxn = 1e4+10; //1e5不行!
const double eps = 1e-8;
const int dx[] = {-1,1,0,0,1,1,-1,-1};
const int dy[] = {0,0,1,-1,1,-1,1,-1};
int dir[2]={-1,1};
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int t,n;
int vis[maxn];
int b[maxn];
int x;
inline int read() //要读入挂!
{
char x;
while((x = getchar())<'0' || x>'9');
int u = x-'0';
while((x = getchar())>='0' && x<='9') u = (u<<3)+(u<<1)+x-'0';
return u;
}
/*
1345 4409 1345 4409 8664 8664
4409 4409 8664 8664=4225(v)
1345 1345 4409 4409=3064(x)
*/
int main()
{
t=read();
while(t--)
{
int f=1;
ms(vis,0);
ms(b,0);
n=read();
int m=0;
for(int i=0;i<n;i++)
{
x=read();
vis[x]++;
if(vis[x]==4 && f)
{
printf("%d %d %d %d\n",x,x,x,x);
f=0;
}
if(vis[x]==2 && f)
b[m++]=x;
}
if(f)
{
sort(b,b+m);
int l,r;
double Min=INF;
for(int i=0;i<m-1;i++)
{
double tmp = (double)b[i]/b[i+1]+(double)b[i+1]/b[i];
if(tmp<Min)
{
Min = tmp;
l=b[i];
r=b[i+1];
}
}
printf("%d %d %d %d\n",l,l,r,r);
}
}
return 0;
}
/*
【题意】
3
4
7 2 2 7
8
2 8 1 4 8 2 1 5
5
5 5 5 5 5
【类型】
【分析】
【时间复杂度&&优化】
【trick】
【数据】
*/
CF1027C Minimum Value Rectangle【贪心/公式化简】的更多相关文章
- CF1027C Minimum Value Rectangle 贪心 数学
Minimum Value Rectangle time limit per test 2 seconds memory limit per test 256 megabytes input stan ...
- CF1027C Minimum Value Rectangle
之前做的时候没想出来...现在来数学推导一波. 题意:从n个木棒中选出4个拼成一个矩形,使得 (周长)2/面积 最小. 解:设矩形宽a长b.我们要最小化下面这个式子: 去掉常数,不妨设b = a + ...
- [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 ...
- 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 ...
- [zoj3813]Alternating Sum 公式化简,线段树
题意:给一个长度不超过100000的原串S(只包含数字0-9),令T为将S重复若干次首尾连接后得到的新串,有两种操作:(1)修改原串S某个位置的值(2)给定L,R,询问T中L<=i<=j& ...
- 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: ...
- 【CF1027C】Minimum Value Rectangle(贪心,数学)
题意:给定n根木棍,不允许拼接或折断,选择四根组成矩形,求所有合法矩形中周长平方与面积比最小的一个,输出拼成这个矩形的四根木棍 n<=1e6 思路:猜结论:答案必定从相邻的4根中产生 证明见ht ...
随机推荐
- cssText基本使用及注意事项
一.cssText之起步 那些年,我们是这样设置样式的: xxx.style.width = "233px"; xxx.style.position = "fixed&q ...
- 耗子学Python了(2)__Python开发“Hello World”
一:开发工具 在网上看到的用的开发工具Aptana Studio,我下载的是Aptana_Studio_3_Setup_3.6.1.exe,在安装的过程中啊,出现了各种问题,然后安装后了也出现打不开的 ...
- J2EE保留小数问题
如果在前台页面,可以直接使用js的toFixed() 方法.number.toFixed(x) 可把 Number 四舍五入为指定小数位数的数字.参数x :必需.规定小数的位数,是 0 ~ 20 之 ...
- 【NOIP】提高组2012 国王游戏
[题意] 恰逢H国国庆,国王邀请n位大臣来玩一个有奖游戏.首先,他让每个大臣在左.右 手上面分别写下一个整数,国王自己也在左.右手上各写一个整数.然后,让这n位大臣排 成一排,国王站在队伍的最前面.排 ...
- Spring理论基础-面向切面编程
AOP是Aspect-Oriented Programming的缩写,中文翻译是面向切面编程.作为Spring的特征之一,是要好好学习的. 首先面向切面编程这个名称很容易让人想起面向对象编程(OOP) ...
- js刷新页面方法 -- (转)
1,reload 方法,该方法强迫浏览器刷新当前页面. 语法:location.reload([bForceGet]) 参数: bForceGet, 可选参数, 默认为 false,从客户端缓存里 ...
- Bitmap算法应用实例(转)
关于数据库查询工作,例如有如下数据库表 要想统计所有90后的程序员该怎么做呢?用一条求交集的SQL语句即可: Select count(distinct Name) as 用户数 from table ...
- 一个简单爬免费代理IP的脚本
- 简谈const限定符
const修饰的数据类型是常量类型,常量类型的对象和变量在定义初始化后是不能被更新的.其实只用记住这一个概念,就可以明白const操作对象的方法. 1)定义const常量 最简单的: const in ...
- BP神经网络-- 基本模型
转载:http://www.cnblogs.com/jzhlin/archive/2012/07/28/bp.html BP 神经网络中的 BP 为 Back Propagation 的简写,最早它 ...