大致题意:
给出一个多边形,问你有多少种放法可以使得多边形稳定得立在平面上。
先对多边形求重心,在求凸包,枚举凸包的边,如果重心没有在边的范围内,则不行
判断是否在范围内可用点积来判断
1 #include 2 #include 3 #include 4 #include 5 #include 6 #include<set> 7 #include 8 #include 9 #include 10 #include 11 #include 12 #include 13 using namespace std; 14 #define MAXN 100100 15 #define eps 1e-9 16 #define For(i,a,b) for(int i=a;i<=b;i++) 17 #define Fore(i,a,b) for(int i=a;i>=b;i--) 18 #define lson l,mid,rt<<1 19 #define rson mid+1,r,rt<<1|1 20 #define mkp make_pair 21 #define pb push_back 22 #define cr clear() 23 #define sz size() 24 #define met(a,b) memset(a,b,sizeof(a)) 25 #define iossy ios::sync_with_stdio(false) 26 #define fre freopen 27 #define pi acos(-1.0) 28 #define inf 1e6+7 29 #define Vector Point 30 const int Mod=1e9+7; 31 typedef unsigned long long ull; 32 typedef long long ll; 33 int dcmp(double x){ 34 if(fabs(x)<=eps) return 0; 35 return x<0?-1:1; 36 } 37 struct Point{ 38 double x,y; 39 Point(double x=0,double y=0):x(x),y(y) {} 40 bool operator < (const Point &a)const{ 41 if(x==a.x) return y<a.y; 42 return x<a.x; 43 } 44 Point operator - (const Point &a)const{ 45 return Point(x-a.x,y-a.y); 46 } 47 Point operator + (const Point &a)const{ 48 return Point(x+a.x,y+a.y); 49 } 50 Point operator * (const double &a)const{ 51 return Point(x*a,y*a); 52 } 53 Point operator / (const double &a)const{ 54 return Point(x/a,y/a); 55 } 56 void read(){ 57 scanf("%lf%lf",&x,&y); 58 } 59 void out(){ 60 cout<<"debug: "<" "<endl; 61 } 62 bool operator == (const Point &a)const{ 63 return dcmp(x-a.x)==0 && dcmp(y-a.y)==0; 64 } 65 }; 66 double Dot(Vector a,Vector b) { 67 return a.x*b.x+a.y*b.y; 68 } 69 double dis(Vector a) { 70 return sqrt(Dot(a,a)); 71 } 72 double Cross(Point a,Point b){ 73 return a.x*b.y-a.y*b.x; 74 } 75 int ConvexHull(Point *p,int n,Point *ch){ 76 int m=0; 77 For(i,0,n-1) { 78 while(m>1 && Cross(ch[m-1]-ch[m-2],p[i]-ch[m-2])<=0) m--; 79 ch[m++]=p[i]; 80 } 81 int k=m; 82 Fore(i,n-2,0){ 83 while(m>k && Cross(ch[m-1]-ch[m-2],p[i]-ch[m-2])<=0) m--; 84 ch[m++]=p[i]; 85 } 86 if(n>1) m--; 87 return m; 88 } 89 int n,m; 90 Point p[100005]; 91 Point ch[100005]; 92 Point cp; 93 void solve(){ 94 scanf("%d",&n); 95 For(i,0,n-1) p[i].read(); 96 double tar=0,ar; 97 cp.x=0;cp.y=0; 98 For(i,2,n-1){ 99 ar=Cross(p[i]-p[0],p[i-1]-p[0])/2; 100 tar+=ar; 101 cp=cp+(p[i]+p[i-1]+p[0])*ar; 102 } 103 cp=cp/tar/3; 104 sort(p,p+n); 105 m=ConvexHull(p,n,ch); 106 int ans=0; 107 For(i,0,m-1) { 108 int nxt=(i+1)%m; 109 if(dcmp(Dot(ch[i]-ch[nxt],cp-ch[nxt]))>0 && dcmp(Dot(ch[nxt]-ch[i],cp-ch[i]))>0) ans++; 110 } 111 printf("%d\n",ans); 112 } 113 int main(){ 114 // fre("in.txt","r",stdin); 115 int t=0; 116 cin>>t; 117 For(i,1,t) solve(); 118 return 0; 119 }
转载于:https://www.cnblogs.com/cjbiantai/p/9328274.html