Gym 101047K Training with Phuket's larvae
http://codeforces.com/gym/101047/problem/K
题目:给定n<=2000条绳子,要你找出其中三条,围成三角形,并且要使得围成的三角形面积最小
思路: 考虑一下三角形面积公式1/2a*b*sinO ,那么可以暴力枚举两条边,第三条边要尽量小,为什么呢?因为我要使得O角尽量小。sin值也小了。这是根据小边对小角得到的。所以要找到第一条>a-b的。这样就能使结果最优。这个找可以用二分啦。同理找一个<a+b的
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL; #include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
const int maxn = 2e3+;
double a[maxn];
const double eps = 1e-;
bool same(double a,double b)
{
return fabs(a-b)<eps;
}
double S(double a,double b,double c)
{
double q = (a+b+c)/;
return sqrt(q*(q-a)*(q-b)*(q-c));
}
bool check (double a,double b,double c)
{
if (a-b>=c) return false;
if (a-c>=b) return false;
if (b-c>=a) return false;
return true;
}
void work ()
{
int n;
scanf("%d",&n);
for (int i=;i<=n;++i)
scanf("%lf",&a[i]);
const double gg=-;
double ans = gg;
sort(a+,a++n);
for (int i=;i<=n-;++i)
{
for (int j=i+;j<=n;++j)
{
double find = a[j]-a[i];
int pos = upper_bound(a+,a++n,find)-a;
if (pos!=n+&&pos!=j&&pos!=i&&check(a[i],a[j],a[pos]))
{
if (ans==-) ans=S(a[i],a[j],a[pos]);
else ans=min(ans,S(a[i],a[j],a[pos]));
}
find=a[j]+a[i];
pos = lower_bound(a+,a++n,find)-a;
if (pos!=n+&&pos-!=j&&pos-!=i&&check(a[i],a[j],a[pos-]))
{
if (ans==-) ans=S(a[i],a[j],a[pos-]);
else ans=min(ans,S(a[i],a[j],a[pos-]));
}
}
}
if (same(ans,gg))
{
printf ("-1\n");
return ;
}
printf ("%0.10f\n",ans);
return ;
} int main()
{
#ifdef local
freopen("data.txt","r",stdin);
#endif
int t;
scanf("%d",&t);
while(t--) work();
return ;
}
Gym 101047K Training with Phuket's larvae的更多相关文章
- ACM: Gym 101047K Training with Phuket's larvae - 思维题
Gym 101047K Training with Phuket's larvae Time Limit:2000MS Memory Limit:65536KB 64bit IO F ...
- Gym - 100676G Training Camp (状压dp)
G. Training Camp[ Color: Yellow ]Montaser is planning to train very hard for ACM JCPC 2015; he has p ...
- Codeforces Gym 2015 ACM Arabella Collegiate Programming Contest(二月十日训练赛)
A(By talker): 题意分析:以a(int) op b(int)形式给出两个整数和操作符, 求两个整数是否存在操作符所给定的关系 ,有则输出true,无则输出false: 思路:由于无时间复杂 ...
- 2017ecjtu-summer training #6 Gym 100952D
D. Time to go back time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- Gym - 100162G 2012-2013 Petrozavodsk Winter Training Camp G. Lyndon Words 暴力枚举
题面 题意:如果一个字符串的最小表示法是他自己,他就是一个Lyndon Word. 例如 aabcb 他的循环串有 abcba bcbaa cbaab baabc 其中字典序最小的是他自己 现在给 ...
- ACM: Gym 101047M Removing coins in Kem Kadrãn - 暴力
Gym 101047M Removing coins in Kem Kadrãn Time Limit:2000MS Memory Limit:65536KB 64bit IO Fo ...
- Gym 101915
Gym - 101915A Printing Books 题意:有一本书,从第X页开始,一共用了n位数字,求此书一共多少页.99就是两位数字,100就是三位数字. 思路:直接模拟即可,我用了一个hi ...
- 2016 Al-Baath University Training Camp Contest-1
2016 Al-Baath University Training Camp Contest-1 A题:http://codeforces.com/gym/101028/problem/A 题意:比赛 ...
- Gym - 100283F F. Bakkar In The Army —— 二分
题目链接:http://codeforces.com/gym/100283/problem/F F. Bakkar In The Army time limit per test 2 seconds ...
随机推荐
- bzoj 5120 无限之环 & 洛谷 P4003 —— 费用流(多路增广SPFA)
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=5120 https://www.luogu.org/problemnew/show/P4003 ...
- 问题4:对dict、list、tuple中的元素排序
一)对字典中元素排序 方法一:利用sorted的key参数进行排序 from random import randint date = {k:randint(0, 20) for k in ran ...
- VS Code:快捷方式
转于:vscode: Visual Studio Code 常用快捷键 博主:魚魚 更多操作参见官网:https://code.visualstudio.com/docs/getstarted/key ...
- JAVA 1.5 并发之 ReentrantLock
在文章里我不打算具体讲Lock的实现,对此有兴趣的请点击这篇博文 http://www.blogjava.net/BucketLi/archive/2010/09/30/333471.html 我是一 ...
- php-fpm包的安装与配置
实验环境:CentOS7 [root@~ localhost]#yum -y install php-fpm php-fpm包:用于将php运行于fpm模式 #在安装php-fpm时,一般同时安装如下 ...
- linux日常管理-rsync格式
rsync支持网络到本地,本地到网络,本地到本地拷贝数据,支持增量拷贝.用作备份. man rsync rsync的两大用法.一种是通过shell,一种是deamon. shell pull远程机器 ...
- Zabbix_proxy的架设
一.安装zabbix-proxy与导入数据库 1. 安装 zabbix-server $ sudo rpm -ivh http://repo.zabbix.com/zabbix/3.0/rhel/7/ ...
- JSP编译指令
----------------siwuxie095 编译指令是通知 JSP 引擎的消息,其作用是设置 JSP 程序的属性, 以及由 JSP 生 ...
- sklearn保存模型
# View more python tutorials on my Youtube and Youku channel!!! # Youtube video tutorial: https://ww ...
- Luogu 2839 [国家集训队]middle
感觉这题挺好的. 首先对于中位数最大有一个很经典的处理方法就是二分,每次二分一个数组中的下标$mid$,然后我们把$mid$代回到原来的数组中检查,如果一个数$a_{i} \geq mid$,那么就把 ...