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【贪心/公式化简】的更多相关文章

  1. CF1027C Minimum Value Rectangle 贪心 数学

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

  2. CF1027C Minimum Value Rectangle

    之前做的时候没想出来...现在来数学推导一波. 题意:从n个木棒中选出4个拼成一个矩形,使得 (周长)2/面积 最小. 解:设矩形宽a长b.我们要最小化下面这个式子: 去掉常数,不妨设b = a + ...

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

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

  5. 【leetcode】963. Minimum Area Rectangle II

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

  6. [zoj3813]Alternating Sum 公式化简,线段树

    题意:给一个长度不超过100000的原串S(只包含数字0-9),令T为将S重复若干次首尾连接后得到的新串,有两种操作:(1)修改原串S某个位置的值(2)给定L,R,询问T中L<=i<=j& ...

  7. 963. Minimum Area Rectangle II

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

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

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

  9. 【CF1027C】Minimum Value Rectangle(贪心,数学)

    题意:给定n根木棍,不允许拼接或折断,选择四根组成矩形,求所有合法矩形中周长平方与面积比最小的一个,输出拼成这个矩形的四根木棍 n<=1e6 思路:猜结论:答案必定从相邻的4根中产生 证明见ht ...

随机推荐

  1. mpvue开发小记

    1.组件嵌套组件时,子组件作用域bug 组件A内的slot包含子组件B的话,无法正常使用变量(这种情况下,B组件的template错误地使用了A的作用域). 我的解决方案:减少一层组件提炼,即这种情况 ...

  2. 深入探索C++对象模型(二)

    构造函数语义学(The Semantics of Constructors) Default Constructor的构造操作 对于class X,如果没有任何user-declared constr ...

  3. [USACO06NOV] Roadblocks

    https://www.luogu.org/problem/show?pid=2865 题目描述 Bessie has moved to a small farm and sometimes enjo ...

  4. [Luogu 3701] 「伪模板」主席树

    [Luogu 3701] 「伪模板」主席树 这是一道网络流,不是主席树,不是什么数据结构,而是网络流. 题目背景及描述都非常的暴力,以至于 Capella 在做此题的过程中不禁感到生命流逝. S 向 ...

  5. Java面试知识总结三

    1.SpringMVC在项目中的应用? 1)service层,项目的业务逻辑层,一般先定义一个接口,在写一个实现类,实现所有的接口方法.service的实现类中要加注解@Service(用于标注业务层 ...

  6. Informatica _组件使用介绍及优化

    转载 http://blog.csdn.net/yongjian1092/article/details/52588434 有空自己会写一个关于这方面的文章.

  7. 【点分治练习题·不虚就是要AK】点分治

    不虚就是要AK(czyak.c/.cpp/.pas)  2s 128M  by zhb czy很火.因为又有人说他虚了.为了证明他不虚,他决定要在这次比赛AK. 现在他正在和别人玩一个游戏:在一棵树上 ...

  8. codechef September Challenge 2017 Fill The Matrix

    这道题我们发现0就代表相同1代表少1或者大1 那么我们根据题目连边 如果存在1(边权只为或0)个数为奇数的环就是无解 #include<cstdio> #include<cstrin ...

  9. HDU 1728 逃离迷宫 (广搜)

    题目链接 Problem Description 给定一个m × n (m行, n列)的迷宫,迷宫中有两个位置,gloria想从迷宫的一个位置走到另外一个位置,当然迷宫中有些地方是空地,gloria可 ...

  10. MSSQL 构建临时表SQL

    declare @StartQuarter int declare @StartYear int declare @EndQuarter int declare @EndYear int declar ...