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. 51nod 1450 闯关游戏——期望dp

    题目:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1450 想了半天,不知道不能走的状态(即最后不足m个的状态)怎么办. ...

  2. cs2008中头文件交叉编译的问题

    使用全局变量 使用基类指针定义在头文件中,在实际使用中强制转型为需要的指针,当然应该也可以存为空指针.

  3. Python:内置函数zip()

    zip函数接受任意多个可迭代对象作为参数,将对象中对应的元素打包成一个tuple,然后返回一个可迭代的zip对象. 这个可迭代对象可以使用循环的方式列出其元素 若多个可迭代对象的长度不一致,则所返回的 ...

  4. MyEclipse、Eclipse SVN插件的帐号、密码修改

    问题描述: Eclipse的SVN插件Subclipse做得很好,在svn操作方面提供了很强大丰富的功能.但到目前为止,该插件对svn用户的概念极为淡薄,不但不能方便地切换用户,而且一旦用户的帐号.密 ...

  5. python 基础 列表 小例子

    存主机ip到列表 host_list=[] netip='192.168.1' for hostip in range(1,254): ip = netip +str(hostip) host_lis ...

  6. sharepoint Foundation 2013 error

    安装必须软件时提示以下错误 错误提示日志: 015-05-28 10:40:25 - Request for install time of 应用程序服务器角色.Web 服务器(IIS)角色2015- ...

  7. JDBC编程之数据查询

    ----------------siwuxie095                             JDBC 编程之数据查询             首先下载 MySQL 的 JDBC 驱动 ...

  8. 第五篇 elasticsearch express插入数据

    1.后端 在elasticsearch.js文件夹下添加: function addDocument(document) { return elasticClient.index({ index: i ...

  9. window.parent ,window.top,window.self 详解及parent和opener的区别

    window.parent ,window.top,window.self 详解 在应用有frameset或者iframe的页面时,parent是父窗口,top是最顶级父窗口(有的窗口中套了好几层fr ...

  10. 【转】JAVA输出内容打印到TXT以及不同系统中如何换行

    JAVA输出内容打印到TXT以及不同系统中如何换行 http://xiyang.09.blog.163.com/blog/static/59827615201172552755293/ 2011-08 ...