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的更多相关文章

  1. ACM: Gym 101047K Training with Phuket's larvae - 思维题

     Gym 101047K Training with Phuket's larvae Time Limit:2000MS     Memory Limit:65536KB     64bit IO F ...

  2. Gym - 100676G Training Camp (状压dp)

    G. Training Camp[ Color: Yellow ]Montaser is planning to train very hard for ACM JCPC 2015; he has p ...

  3. Codeforces Gym 2015 ACM Arabella Collegiate Programming Contest(二月十日训练赛)

    A(By talker): 题意分析:以a(int) op b(int)形式给出两个整数和操作符, 求两个整数是否存在操作符所给定的关系 ,有则输出true,无则输出false: 思路:由于无时间复杂 ...

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

  5. Gym - 100162G 2012-2013 Petrozavodsk Winter Training Camp G. Lyndon Words 暴力枚举

    题面 题意:如果一个字符串的最小表示法是他自己,他就是一个Lyndon Word. 例如  aabcb 他的循环串有 abcba  bcbaa cbaab baabc 其中字典序最小的是他自己 现在给 ...

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

  7. Gym 101915

    Gym - 101915A  Printing Books 题意:有一本书,从第X页开始,一共用了n位数字,求此书一共多少页.99就是两位数字,100就是三位数字. 思路:直接模拟即可,我用了一个hi ...

  8. 2016 Al-Baath University Training Camp Contest-1

    2016 Al-Baath University Training Camp Contest-1 A题:http://codeforces.com/gym/101028/problem/A 题意:比赛 ...

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

随机推荐

  1. 【转】Unity3D如何制作落叶效果

    原文地址:http://hi.baidu.com/cupgenie/item/c23861df692f59e3b3f777a8 创建一个粒子系统 GameObject>Create other& ...

  2. Excel对重复数据分组,求出不同的数据(office 2013)

    第一步: 第二步: 第三步:

  3. c++17 filesystem, regex 遍历目录

    linux 遍历目录+文件(优化版本) c++17 FS 还是挺好用的, VS2017支持,但是linux g++7.3 还是不支持 filesystem #include<filesystem ...

  4. pyodbc简单使用

    1.连接数据库 1)直接连接数据库和创建一个游标(cursor) cnxn = pyodbc.connect('DRIVER={SQL Server};SERVER=localhost;DATABAS ...

  5. DES加密/解密

    /// <summary> /// DES加密/解密类. /// </summary> public class DESEncrypt { #region ========加密 ...

  6. R: matrix & array 生成、操作矩阵、数组:

    ################################################### 问题:生成.操作矩阵   18.4.27 怎么生成矩阵 matrix.,,及其相关操作 ??? ...

  7. redis学习总结1

    Redis是一个开源的使用ANSI C语言编写.支持网络.可基于内存亦可持久化的日志型.Key-Value数据库,并提供多种语言的API.和普通的Key-Value结构不同,Redis的Key支持灵活 ...

  8. Cactus项目(又叫MVCAdmin),开源(2016-11-26更新)

    Cactus基于之前简单后台管理的改良版本,完善了权限管理,为后续的扩展和管理做了铺垫. 完全开放代码,可供学习交流 目前采用MVC4+Autofac+Dapper制作而成,集成一个简单的Blog和权 ...

  9. 消息队列--RabbitMQ(二)

    1.常用的几种队列简介 RabbitMQ有五种常用的队列,分别是:简单队列.work模式.发布订阅模式.路由模式.主题(Topic)模式.其实发布订阅.路由.主题这三种模式都从属于与routingke ...

  10. DES的雪崩效应分析

    明文固定,密钥改变一个字节 假定明文为11111111(00000001 00000001 00000001 00000001 00000001 00000001 00000001 00000001) ...