hdu-4946 Area of Mushroom 凸包

来源:互联网 发布:三层网络ping 请求超时 编辑:程序博客网 时间:2024/04/30 05:25

题目链接


#include <stdio.h>#include <string.h>#include <iostream>#include <queue>#include <vector>#include <math.h>#include <algorithm>using namespace std;typedef __int64 LL;const int maxn = 1005;const int Mod = 1000000007;int n,N;int ans[maxn];int mark[maxn];struct Point  {      double x,y,p;    int id;    Point( double x = 0,double y = 0 ): x(x),y(y) { }  }point[maxn],ch[maxn];  typedef Point Vector;  bool cmp( Point A,Point B )  {      //return A.x < B.x || ( A.x == B.x && A.y < B.y );      if( A.x == B.x )          return A.y < B.y;      return A.x < B.x;  }  double Cross( Vector A,Vector B )  {      return A.x * B.y - A.y * B.x;  }  Vector operator - ( Vector A,Vector B )  {      return Vector( A.x - B.x,A.y - B.y );  }  int ConvexHull()  {      sort( point,point+n,cmp );      memset( mark,0,sizeof(mark) );    for( int i = 1; i < n; i ++ )    {        if( point[i].x == point[i-1].x && point[i].y == point[i-1].y ){            mark[point[i].id] = 1; mark[point[i-1].id] = 2;        }    }    int m = 0;      for( int i = 0; i < n; i ++ )      {          if( mark[point[i].id] == 2 )    continue;        while( m > 1 && Cross( ch[m-1]-ch[m-2],point[i]-ch[m-2] ) < 0 )              m --;          ch[m++] = point[i];      }      int k = m;      for( int i = n-2; i >= 0; i -- )      {          if( mark[point[i].id] == 2 )    continue;        while( m > k && Cross( ch[m-1]-ch[m-2],point[i]-ch[m-2] ) < 0 )              m --;          ch[m++] = point[i];      }      if( n > 1 )  m --;      return m;  }  bool cmp1( Point a,Point b ){    return a.p > b.p;}int main(){    #ifndef ONLINE_JUDGE         freopen("data.txt","r",stdin);         #endif     int c = 1;    while( scanf("%d",&N) != EOF,N )    {        int flag = 1;        memset( ans,0,sizeof(ans) );        for( int i = 0; i < N; i ++ )        {            scanf("%lf%lf%lf",&point[i].x,&point[i].y,&point[i].p);            point[i].id = i;        }        sort( point,point+N,cmp1 );        if( point[0].p != 0 )        {            n = N;            for( int i = 1; i < N; i ++ )            {                if( point[i].p != point[i-1].p )                {                    n = i;                    break;                }            }            int m = ConvexHull();             for( int i = 0; i < m; i ++ )                if( !mark[ch[i].id] )                    ans[ch[i].id] = 1;        }        printf("Case #%d: ",c ++);        for( int i = 0; i < N; i ++ )            printf("%d",ans[i]);        puts("");    }    return 0;}


0 0
原创粉丝点击