Gym 101047K Training with Phuket's larvae

Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u

Description

standard input/output

Thai cuisine is known for combining seasonings so that every dish has flavors that are sweet (sugar, fruits, bell peppers), spicy, sour (vinegar, tamarind, lime), and salty (soy sauce, fish sauce). The most exotic dish, however, is the one containing fried insect larvae; naturally, it is often showcased to tourists. Westerners usually shudder at the thought of eating larvae, but they are highly valued in Thailand and they are a huge success in parties. Thai children often play with food. They specially like building triangles up using fried larvae as the edges.

Marcos "the (Rubik) solver" coaches his university's team on a famous computer programming contest. Next year, the contest's world finals will take place in Phuket, Thailand.

Marcos knows how Thai children like to play with larvae, so he had an idea for a special training session. His idea involves preparing a large amount of fried larvae of several different lengths. Each of his friends, in turn, must select three larvae to build a triangle. Then, the amount of fried larvae each friend has to eat is proportional to the area of the triangle she or he built.

Marcos hopes that, since you want to eat as little larvae as possible, you'll write a program to choose the larvae that forms a triangle of minimum area. Thus, besides training your computer programming skills, you'll also be training to face Thai cuisine. If you actually enjoy this dish, you may use this program to help your other friends, making sure that there will be more fried larvae left for you.

Input

The first line has a single integer T, the number of test cases.

Each test case starts with an integer N, the number of larvae. In the next line there are N space-separated real numbers a1, ..., an, representing the lengths of the larvae.

Limits

  • 1 ≤ T ≤ 30
  • 1 ≤ N ≤ 2·103
  • 1 ≤ ai ≤ 500
  • The sum of N over all test cases will not exceed 6·103

Output

For each test case, print a single line containing the minimum area for that case, the error should not exceed 10 - 4; if it is not possible to build a triangle from the larvae, print -1.

Sample Input

Input
3
4
3 4 5 6
3
1 2 4
5
3.4 2.8 7.1 5.2 10
Output
5.3326822519
-1
4.3599885321
/*/
题意:
给你n条边,问这n条边构成的三角形的面积最小是多少。 题意很简单,想着暴力,一看复杂度 O(8*n^3) ... 让我冷静下。。 然后想到枚举两条边用二分第三条边~TLE 噗。。 后面考虑了很久,要求最小的面积,只有三角形是那种细长细长的才能最小,又枚举 i 和 j 是按照顺序来枚举的,只要找到,比 i+j 小一点点的的就行了。 用到lower_bound( , , );函数; AC代码:
/*/
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <bitset>
#include <string>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <functional>
#define debug(x) cout<<"["<<x<<"]";
#define FIN freopen("input.txt","r",stdin);
#define FOUT freopen("output.txt","w+",stdout);
//#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int MAX=1e5+5; double Check(double a,double b,double c) {
double s;
double p=(a+b+c)/2;
return s=sqrt((p-a)*(p-b)*(p-c)*p);
} int main() {
int T;
double a[MAX];
cin>>T;
while(T--) {
int n;
scanf("%d",&n);
for(int i=0; i<n; i++) {
scanf("%lf",&a[i]);
}
double ans=1e9+10000;
sort(a,a+n);
for(int i=0; i<n; i++) {
for(int j=i+1; j<n-1; j++) {
if(a[i]+a[j]>a[j+1]) ans=min(ans,Check(a[i],a[j],a[j+1]));
int k=lower_bound(a+j,a+n,a[i]+a[j])-a-1;
if(k>j&&a[k]<a[i]+a[j]) ans=min(ans,Check(a[i],a[j],a[k]));
}
}
if(ans!=1e9+10000)
printf("%.10lf\n",ans);
else
printf("-1\n");
}
return 0;
}

  

 

ACM: Gym 101047K Training with Phuket's larvae - 思维题的更多相关文章

  1. Gym 101047K Training with Phuket's larvae

    http://codeforces.com/gym/101047/problem/K 题目:给定n<=2000条绳子,要你找出其中三条,围成三角形,并且要使得围成的三角形面积最小 思路: 考虑一 ...

  2. UVA 1394 And Then There Was One / Gym 101415A And Then There Was One / UVAlive 3882 And Then There Was One / POJ 3517 And Then There Was One / Aizu 1275 And Then There Was One (动态规划,思维题)

    UVA 1394 And Then There Was One / Gym 101415A And Then There Was One / UVAlive 3882 And Then There W ...

  3. HDU 6298.Maximum Multiple-数学思维题(脑子是个好东西,可惜我没有) (2018 Multi-University Training Contest 1 1001)

    暑假杭电多校第一场,这一场是贪心场,很多贪心的题目,但是自己太菜,姿势挫死了,把自己都写吐了... 2018 Multi-University Training Contest 1 HDU6298.M ...

  4. 思维题 Gym 100553A Alter Board

    题目传送门 /* 题意:一个n×m的矩形,相邻的颜色不同,黑或白.问最少的翻转次数,每次翻转可指定任意一个子矩形 思维题:最少要把偶数行和列翻转,也就是n/2+m/2次 */ #include < ...

  5. Codeforces Gym 102392F Game on a Tree (SEERC2019 F题) 题解

    题目链接:https://codeforces.com/gym/102392/problem/F 题意:被这题题意坑了很久,大意是说有一棵根为 \(1\) 的树,每个节点初始都是白色, \(Alice ...

  6. ACM思维题训练 Section A

    题目地址: 选题为入门的Codeforce div2/div1的C题和D题. 题解: A:CF思维联系–CodeForces -214C (拓扑排序+思维+贪心) B:CF–思维练习-- CodeFo ...

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

  8. ACM: Gym 100935F A Poet Computer - 字典树

    Gym 100935F A Poet Computer Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d &am ...

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

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

随机推荐

  1. URI编码解码

    .NET string s= System.Web.HttpUtility.UrlEncode("123", System.Text.Encoding.Unicode); //编码 ...

  2. tail命令详解

    搜索 纠正错误  添加实例 tail 在屏幕上显示指定文件的末尾若干行 补充说明 tail命令 用于输入文件中的尾部内容.tail命令默认在屏幕上显示指定文件的末尾10行.如果给定的文件不止一个,则在 ...

  3. 耿丹CS16-2班助教总结

    Deadline: 2016-1-7 11:59pm 开篇有言 --又是一年末,不似风光,却添风霜,顶霾前进,踽踽独行,可乎? 助教那些事儿 助教这份工作是之前就担任过的,很羞愧,当时才担任了几天就撒 ...

  4. MySQL 排名统计

    select actor_id,@curr_cnt:=cnt as cnt , ,@rank) as rank, @prev_cnt:=@curr_cnt as dummy from( select ...

  5. linux du和df

    df.du和fdisk这三个常用命令:df用于检查文件系统磁盘占用情况,du检查磁盘空间占用情况,而fdisk用于磁盘分区. du,disk usage,是通过搜索文件来计算每个文件的大小然后累加,d ...

  6. PHP Ueditor 富文本编辑器

    2016年12月11日 08:46:59 星期日 百度的简版富文本编辑器umeditor很久没更新了 全功能版本的配置项跟umeditor还是有区别的, 这里说下ueditor怎么对接到项目中去, 主 ...

  7. selenium 常见面试题以及答案(Java版)

    1.怎么 判断元素是否存在? 判断元素是否存在和是否出现不同, 判断是否存在意味着如果这个元素压根就不存在, 就会抛出NoSuchElementException 这样就可以使用try catch,如 ...

  8. 读取Simulink中Dataset类型的数据

    http://files.cnblogs.com/files/pursuiting/%E5%80%92%E7%AB%8B%E6%91%86%E6%8E%A7%E5%88%B6%E7%B3%BB%E7% ...

  9. 五种方式让你在java中读取properties文件内容不再是难题

    一.背景 最近,在项目开发的过程中,遇到需要在properties文件中定义一些自定义的变量,以供java程序动态的读取,修改变量,不再需要修改代码的问题.就借此机会把Spring+SpringMVC ...

  10. pem转换成der

    openssl x509 -in xxxxx.pem -inform PEM -out xxxx.der -outform DER [root@NB Desktop]# file xxxx.der