HDU 4709 Herding(热身赛第四题)

转载请注明出处:http://blog.csdn.net/a1dark

分析:最开始用海伦公式、各种错、判断了三点一线还是错、无语了、最后实在不行、放弃了海伦公式。。。

#include<stdio.h>
#include<string.h>
#include<math.h>
#include<iostream>
using namespace std;
const double inf = 999999.0;
struct Point{
    double x,y;
}point[105];
double s(Point a,Point b,Point c){
    return ((b.x - a.x) * (c.y - a.y) - (b.y - a.y)*(c.x - a.x))/2;
}
int main(){
    int ncase;
    scanf("%d",&ncase);
    double ans,tmp;
    while(ncase--){
        bool flag = false;
        tmp = 0.0;
        ans = inf;
        int n;
        scanf("%d",&n);
        for(int i = 0 ; i < n ; i++){
            scanf("%lf %lf",&point[i].x,&point[i].y);
        }
        for(int i = 0 ; i < n ; i++){
            for(int j = 0 ; j < n ; j++ ){
                if( i != j){
                    for(int k = 0  ; k < n ; k++){
                        if( k != j && k != i){
                            tmp = s(point[i],point[j],point[k]);
                            tmp = fabs(tmp);
                            if(tmp < ans &&tmp!=0){
                                ans = tmp;
                                flag = true;
                            }
                        }
                    }
                }
            }
        }
        if(flag){
            printf("%.2lf\n",ans);
        }
        else{
            printf("Impossible\n");
        }
    }
    return 0;
}


你可能感兴趣的:(数学,ACM)