zoukankan      html  css  js  c++  java
  • 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 }
  • 相关阅读:
    php利用__callStatic静态调用同类中非静态方法
    Using $this when not in object context错误原因及解决办法
    fastadmin权限修改
    call_user_func()
    php empty()奇怪现象
    LF will be replaced by CRLF in vendor/
    git放弃本地,强制拉取远程
    tp5防xss攻击方法
    php curl
    关于Mac设置alias别名访问服务器
  • 原文地址:https://www.cnblogs.com/Bang-cansee/p/3724025.html
Copyright © 2011-2022 走看看