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. 排成一行的li之间的间隙问题

    现象 对于ul下li排成一行的布局(即li的display由list-item设为inline-block): 情况1 如果这些li在书写的时候有换行或者有空格,且ul本身的font-size不为0, ...

  2. STL string大小写 转换

    std::string data = "This is a sample string."; // convert string to upper case std::for_ea ...

  3. 新版 Spring下载方法

    1.百度 Spring 打开官方网站   http://spring.io/ 2.======================================= 3.================= ...

  4. T-SQL操作XML 数据类型方法 "modify" 的参数 1 必须是字符串文字。

    ----删除关键字的同时也清理AP表中所有关联这个ID的数据 create trigger Trg_UpdateAppWordOnDelKeyWord on [dbo].[tbl_KeyWord] f ...

  5. 字符串(String)

    字符串是由字符组成的数组,但在JavaScript中字符串是不可变的:可以访问字符串任意位置的文本,但是JavaScript并未提供修改已知字符串内容的方法. 常见功能: obj.length     ...

  6. Java Learning 001 新建一个Java工程 HelloWorld程序

    Java Learning 001 新建一个Java工程 HelloWorld程序 Step 1 . 在Eclipse 软件里,点击: File -> New -> Java Projec ...

  7. PHP中ob_start()函数的用法

    ob_start()函数用于打开缓冲区,比如header()函数之前如果就有输出,包括回车/空格/换行/都会有"Header had all ready send by"的错误,这 ...

  8. JAVA IO包的整理---------Exception

    EOFException Signals that an end of file or end of stream has been reached unexpectedly during input ...

  9. DESede/CBC/PKCS5Padding

    Java.security.NoSuchAlgorithmException: Cannot find any provider supporting DESede/CBC/PKCS5Padding ...

  10. 从零开始安装 Ambari (2) -- 准备本地 repository

    安装 Ambari,最后是为了用它部署 hadoop 集群.安装时默认使用的是 hortonworks 远程的资源,用它部署集群时,需要下载 Hadoop.Hive.HBase 的安装包,速度很慢.我 ...