hdu-4946 Area of Mushroom 凸包

题目链接


#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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值