F - Herding
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
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.
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
1 4 -1.00 0.00 0.00 -3.00 2.00 0.00 2.00 2.00
Sample Output
2.00
____
水题,直接枚举就可过。。
忘了用EPS 浮点数误差有问题
还有就是卡了一下输入,一开始判断n<3直接就CONTINUE了,这样接下来其他数据会出错。
代码如下:
#include<cstdio> #include<algorithm> #include<cmath> #include<iostream> using namespace std ; #define N 110 #define eps 1e-8 struct { doublex,y; } array[N]; double area( double x1 , double y1 , doublex2 , double y2 ,double x3 , double y3 ) { returnfabs( 0.5 * ( x1*y2+x3*y1+x2*y3-x3*y2-x1*y3-x2*y1) ) ; } int main() { intt ; cin>> t ; for(int i = 1 ; i<= t ; i++) { intn ; cin>> n ; for(int i = 1 ; i<= n ; i++) cin>> array[i].x >> array[i].y; if(n < 3 ) { cout<<"Impossible" << endl ; continue; } doublemin = 99999999; intflag = 1; for(int i = 1 ; i <=n; i++) { for(int j = i+1 ; j<=n ; j++) { for(int k = j+1 ; k<= n; k++) { doubletemp = area( array[i].x , array[i].y ,array[j].x,array[j].y,array[k].x,array[k].y) ; if(fabs(temp) >= eps && temp <= min) { min= temp ; flag= 0 ; } } } } if(flag == 0 ) printf("%.2lf\n",min); else cout<<"Impossible" << endl ; } return0 ; }