[ACM]hdu Herding(枚举+三角形面积)
来源:互联网 发布:有关红酒的网络广告语 编辑:程序博客网 时间:2024/05/22 11:51
Herding
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 5 Accepted Submission(s) : 2
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
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
Source
2013 ACM/ICPC Asia Regional Online —— Warmup
解题思路:
本题就是给定几个点,然后从中选择几个点围成一定的面积,要求这个最小的面积,一开始想复杂了,以为四个或五个的点也能组成最小面积,其实最小的是三个点,因为四个或五个点其中里面选三个点肯定面积要小,所以本题的本质也就是求最小三角形的面积。
代码:
#include <iostream>#include <cmath>#include <iomanip>using namespace std;struct point{ double x,y;}p[103];//构造点double area(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; cin>>t; for(int ni=1;ni<=t;ni++) { cin>>n; for(int i=1;i<=n;i++) cin>>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=area(p[i],p[j],p[k]); if(temp<Min&&temp!=0)//temp不为0才能构成三角形 { Min=temp; flag=1; } } } } if(flag) cout<<setiosflags(ios::fixed)<<setprecision(2)<<Min<<endl; else cout<<"Impossible"<<endl; } return 0;}
要点:给定三个点,求其面积
double area(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;}
即求行列式
1 1 1
x1 x2 x3
y1 y2 y3
0 0
- [ACM]hdu Herding(枚举+三角形面积)
- hdu4709 herding 计算几何 三角形面积 枚举
- hdu 4709 - Herding【计算几何-三角形面积】
- HDU 4709 Herding(求三角形面积)
- HDU 4709 Herding(叉积求三角形面积)
- hdu 4709 Herding acm
- ACM-三角形面积
- AYIT2016省赛集训第五周 A - Herding(三角形面积)
- HDU 2036 叉乘求三角形面积
- [ACM] HDU 5135 Little Zu Chongzhi's Triangles (一堆木棍组成三角形最大面积)
- 【枚举】求三角形最大面积问题
- 南阳理工ACM 题目67 三角形面积
- hdu 4709 Herding
- hdu - 4709 - Herding
- HDU 4709 Herding
- hdu 4709 Herding
- HDU 4709 Herding
- HDU 4709 Herding
- 小马哥2013年口述精华:移动互联网是一场巨大的颠覆
- dddd
- IOS:视频
- Encoding.GetEncoding 编码列表 .
- FreeBSD使用英汉辞典
- [ACM]hdu Herding(枚举+三角形面积)
- 经典排序算法之——快速排序
- mySQL中删除unique key的语法 (删除某个字段的唯一性)
- linux术语解析(持续更新)
- js 函数的执行环境和作用域链的深入解析
- 自己动手写RTP服务器——用RTP协议传输TS流
- ubuntu 字体设置像Windows 字体
- AVCaptureDevice
- Android与PC通信之Socket