您的位置:首页 > 其它

HDU 4709 Herding

2013-09-12 17:14 405 查看
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4709

思路:求最小的三角形面积,easy~~~~

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <algorithm>
using namespace std;
#define maxn 110
#define inf 0x3f3f3f3f
typedef struct point{
double x,y;
}P;
P node[maxn];

double Distance(point a,point b){
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}

int main()
{
int T,n;
while(~scanf("%d",&T)){
while(T--){
scanf("%d",&n);
for(int i=0;i<n;i++){
scanf("%lf %lf",&node[i].x,&node[i].y);
}
if(n<3){
printf("Impossible\n");
continue;
}
double ans = inf ;
double a,b,c,p,temp;
for(int i=0;i<n;i++){
for(int j =i+1;j<n;j++){
for(int k=j+1;k<n;k++){
a=Distance(node[i],node[j]);
b=Distance(node[i],node[k]);
c=Distance(node[j],node[k]);
p =(a+b+c)/2;
temp=p*(p-a)*(p-b)*(p-c);
temp=sqrt(temp);
if(temp>=0.05 && temp<ans) ans = temp;
}
}
}
if(ans == inf) printf("Impossible\n");
else
printf("%.2lf\n",ans);
}
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  HDU