poj 1228 Grandpa's Estate 凸包

  
http://poj.org/problem?id=1228
1
/** 2 大意:给定n个点看能否确定出凸包。。 数据有点若 3 思路: 求出凸包后 查看每条边上是否有至少三个点。。因为一条边上有两个电时,并不能确定出凸包,还能进行扩充 4 学习之处: 自己做的时候是挨个枚举的每条边,数出其上的点,一直WA ,,找了个题解,, 5 **/ 6 #include <iostream> 7 #include <algorithm> 8 #include <cmath> 9 #include <cstring> 10 using namespace std; 11 const double eps = 1e-8; 12 int fla[1010]; 13 int flag1[1010]; 14 int dcmp(double x){ 15 if(fabs(x)<eps) 16 return 0; 17 else 18 return x<0?-1:1; 19 } 20 21 struct point { 22 double x,y; 23 point (double x=0,double y=0):x(x),y(y){} 24 }; 25 point p[1010]; 26 int ch[1010]; 27 typedef point Vector; 28 29 Vector operator -(point a,point b){ 30 return Vector (a.x-b.x,a.y-b.y); 31 } 32 double cross(Vector a,Vector b){ 33 return a.x*b.y-a.y*b.x; 34 } 35 double dot(Vector a,Vector b){ 36 return a.x*b.x+a.y*b.y; 37 } 38 bool cmp(point a,point b){ 39 if(a.x==b.x) 40 return a.y<b.y; 41 return a.x<b.x; 42 } 43 44 int convexHull(point *p,int n,int *ch){ 45 sort(p,p+n,cmp); 46 int m =0; 47 for(int i=0;i<n;i++){ 48 while(m>1&&dcmp(cross(p[ch[m-1]]-p[ch[m-2]],p[i]-p[ch[m-2]]))<=0) 49 m--; 50 ch[m++] = i; 51 } 52 int k =m; 53 for(int i=n-2;i>=0;i--){ 54 while(m>k&&dcmp(cross(p[ch[m-1]]-p[ch[m-2]],p[i]-p[ch[m-2]]))<=0) 55 m--; 56 ch[m++] = i; 57 } 58 if(n>1) m--; 59 return m; 60 } 61 62 int main() 63 { 64 int t; 65 cin>>t; 66 while(t--){ 67 // memset(req,0,sizeof(req)); 68 int n; 69 cin>>n; 70 71 for(int i=0;i<n;i++){ 72 cin>>p[i].x>>p[i].y; 73 } 74 if(n<6){ 75 cout<<"NO"<<endl; 76 continue; 77 } 78 int res = convexHull(p,n,ch); 79 memset(fla,0,sizeof(fla)); 80 memset(flag1,0,sizeof(flag1)); 81 for(int i=0;i<res;i++) 82 fla[ch[i]] =1; 83 for(int i=0;i<n;i++)if(!fla[i]){ 84 for(int j=1;j<res;j++){ 85 if(dcmp(cross(p[ch[j-1]]-p[i],p[ch[j]]-p[i]))==0){ 86 flag1[j-1]+=2; 87 flag1[j] += 1; 88 } 89 } 90 if(dcmp(cross(p[ch[res-1]]-p[i],p[ch[0]]-p[i]))==0) 91 flag1[res-1]+=2,flag1[0]+=1; 92 } 93 int flag =1; 94 for(int i=0;i<res;i++){ 95 if(flag1[i]<3){ 96 flag =0; 97 break; 98 } 99 } 100 if(flag) 101 cout<<"YES"<<endl; 102 else 103 cout<<"NO"<<endl; 104 105 } 106 return 0; 107 }

 

转载于:https://www.cnblogs.com/Bang-cansee/p/3724025.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值