假设逆时针时针分别为ABCDE
判断能组成五角星 等价于凸包的点还是这5个点
然后答案=S(ACE)+S(ABE)-S(ABE)
就结束了。
1 #include<stdio.h> 2 #include<math.h> 3 #include<string.h> 4 #include<iostream> 5 #include<algorithm> 6 #include<map> 7 #include<set> 8 #include<queue> 9 #include<stack> 10 #define FOR(i,n) for(i=0;i<(n);i++) 11 #define CLR(a) memset(a,0,sizeof(a)) 12 #define CIN(a) scanf("%d",&a) 13 typedef long long ll; 14 using namespace std; 15 double _x,_y; 16 double Cos(double x,double y){ 17 return x/sqrt(y*y+x*x); 18 } 19 struct point{ 20 double x,y; 21 point(double xx,double yy){x=xx;y=yy;} 22 point(){} 23 point operator-(const point &p){ 24 return point(x-p.x,y-p.y); 25 } 26 bool operator<(const point &p) const{ 27 return Cos((x-_x),(y-_y))>Cos((p.x-_x),(p.y-_y)); 28 } 29 double operator*(const point &p){ 30 return x*p.y-p.x*y; 31 } 32 }; 33 point p[5]; 34 void sw(int i,int j){ 35 point x=p[i]; 36 p[i]=p[j]; 37 p[j]=x; 38 } 39 int pan(){ 40 //printf("%lf %lf\n",(p[2]-p[1])*(p[3]-p[2]),(p[3]-p[2])*(p[4]-p[3])); 41 return (p[2]-p[1])*(p[3]-p[2])>0&&(p[3]-p[2])*(p[4]-p[3])>0; 42 } 43 double S(int i,int j,int k){ 44 return fabs((p[j]-p[i])*(p[k]-p[i])/2); 45 } 46 int main() 47 { 48 int t,i; 49 //freopen("1.in","r",stdin); 50 //freopen("1.out","w",stdout); 51 scanf("%d",&t); 52 while(t--){ 53 int mini=0; 54 for(i=0;i<5;i++){ 55 scanf("%lf%lf",&p[i].x,&p[i].y); 56 } 57 for(i=1;i<5;i++){ 58 if(p[i].y<p[mini].y) mini=i; 59 } 60 sw(i,mini); 61 _x=p[0].x; 62 _y=p[0].y; 63 sort(p+1,p+5); 64 //for(i=0;i<5;i++){ 65 //printf("%lf,%lf\n",p[i].x,p[i].y); 66 67 if(pan()){ 68 printf("%.5lf\n",S(0,2,4)+S(0,1,3)-S(0,1,4)); 69 }else{ 70 printf("-1\n"); 71 } 72 } 73 return 0; 74 }
时间: 2024-10-13 23:51:17