HDU 4709 Herding
来源:互联网 发布:php字符串截取中文 编辑:程序博客网 时间:2024/05/19 13:08
Little John is herding his father's cattles. As a lazy boy, he cannot tolerate chasing the cattles all the time to avoid unnecessary omission. Luckily, he notice that there were N trees in the meadow numbered from 1 to N, and calculated their cartesian coordinates (Xi, Yi). To herding his cattles safely, the easiest way is to connect some of the trees (with different numbers, of course) with fences, and the close region they formed would be herding area. Little John wants the area of this region to be as small as possible, and it could not be zero, of course.
Input
The first line contains the number of test cases T( T<=25 ). Following lines are the scenarios of each test case.
The first line of each test case contains one integer N( 1<=N<=100 ). The following N lines describe the coordinates of the trees. Each of these lines will contain two float numbers Xi and Yi( -1000<=Xi, Yi<=1000 ) representing the coordinates of the corresponding tree. The coordinates of the trees will not coincide with each other.
The first line of each test case contains one integer N( 1<=N<=100 ). The following N lines describe the coordinates of the trees. Each of these lines will contain two float numbers Xi and Yi( -1000<=Xi, Yi<=1000 ) representing the coordinates of the corresponding tree. The coordinates of the trees will not coincide with each other.
Output
For each test case, please output one number rounded to 2 digits after the decimal point representing the area of the smallest region. Or output "Impossible"(without quotations), if it do not exists such a region.
Sample Input
14-1.00 0.000.00 -3.002.00 0.002.00 2.00
Sample Output
2.00
求其中三个点组成的面积最小值
#include <iostream>#include <cmath>#include <iomanip>using namespace std;struct point{ double x,y;}p[500];double get(point p1,point p2,point p3){ return abs(p1.x*p2.y+p1.y*p3.x+p2.x*p3.y-p2.y*p3.x-p1.x*p3.y-p1.y*p2.x)/2.0;}int main(){ int t,n; scanf("%d",&t); for(int ni=1;ni<=t;ni++) { scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%lf%lf",&p[i].x,&p[i].y); int flag=0; double min=9999999; for(int i=1;i<=n;i++) { for(int j=i+1;j<=n;j++) { for(int k=j+1;k<=n;k++) { double temp=get(p[i],p[j],p[k]); if(temp<min&&temp!=0) { min=temp; flag=1; } } } } if(flag)printf("%.2lf\n",min); else puts("Impossible"); } return 0;}
0 0
- hdu 4709 Herding
- hdu 4709 Herding acm
- hdu - 4709 - Herding
- HDU 4709 Herding
- hdu 4709 Herding
- HDU 4709 Herding
- HDU 4709 Herding
- HDU - 4709 Herding
- HDU 4709 Herding
- hdu 4709 Herding (数学)
- HDU 4709 Herding
- HDU 4709 Herding
- HDU 4709 Herding
- hdu 4709 Herding
- HDU 4709:Herding
- HDU 4709 Herding
- hdu 4709 Herding
- hdu 4709 Herding
- HDU 1158 Employment Planning
- hdu 5402 Travelling Salesman Problem (构造)
- 【Android】pull解析xml文件+将数据存储为xml格式,并保存在内存里
- Extjs 4.2 实现文本框组 支付宝支付密码输入效果
- 交叉编译的configure
- HDU 4709 Herding
- Linux 静态IP地址设置
- 简单Core Animation
- 二分之查找
- jquery选中多个标签、选中多个class的标签
- 通用权限管理设计篇
- codeforces 569A__Music
- 任意2n个整数,从其中选出n个整数,使得选出的n个整数和同剩下的n个整数之和的差最小。
- Android View的小结