首页 > 代码库 > hdu 4946 待敲tomo
hdu 4946 待敲tomo
http://acm.hdu.edu.cn/showproblem.php?pid=4946
http://blog.csdn.net/hcbbt/article/details/38582243
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#define MAXX 510
#define eps 1e-8
using namespace std;
typedef struct point
{
double x,y;
int v;
}point;
bool dy(double x,double y){ return x>y+eps; }
bool xy(double x,double y){ return x<y-eps; }
bool dyd(double x,double y){ return x>y-eps; }
bool xyd(double x,double y){ return x<y+eps; }
bool dd(double x,double y){ return fabs(x-y)<eps; }
double crossProduct(point a,point b,point c)
{
return (c.x-a.x)*(b.y-a.y)-(c.y-a.y)*(b.x-a.x);
}
double dist(point a,point b)
{
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
point p[MAXX];
point stk[MAXX];
int top;
bool cmp(point a,point b)
{
double len=crossProduct(p[0],a,b);
if(dd(len,0.0))
return xy(dist(p[0],a),dist(p[0],b));
return xy(len ,0.0);
}
void Graham(int n)
{
int tmp=0;
for(int i=1; i<n; i++)
{
if(xy(p[i].x,p[tmp].x) || dd(p[i].x,p[tmp].x) && xy(p[i].y,p[tmp].y))
tmp=i;
}
swap(p[0],p[tmp]);
sort(p+1,p+n,cmp);
stk[0]=p[0];
stk[1]=p[1];
top=1;
for(int i=2; i<n; i++)
{
if(top && xyd(crossProduct(stk[top],stk[top-1],p[i]),0.0))
top--;
stk[++top]=p[i];
}
}
int main()
{
int n,m,i,j;
int mark=1;
while(scanf("%d",&n)!=EOF && n)
{ int ss[MAXX];
memset(ss,0,sizeof(ss));
point tmp[MAXX];
int maxx=0;
for(i=0; i<n; i++)
{
scanf("%lf%lf%d",&tmp[i].x,&tmp[i].y,&tmp[i].v);
if(tmp[i].v>maxx)
maxx=tmp[i].v;
}
if(maxx == 0)
{
printf("Case #%d: ",mark++);
for(i=0; i<n; i++)
printf("%d",ss[i]);
printf("\n");
continue;
}
int cas=0,cas1=1;
for(i=0; i<n; i++)
{
if(tmp[i].v == maxx)
{
p[cas].x=tmp[i].x;
p[cas].y=tmp[i].y;
p[cas++].v=tmp[i].v;
}
}
sort(p,p+cas,cmp);
for(i=0; i<cas-1; i++)
{
if(p[i].x != p[i+1].x || p[i].y != p[i+1].y)
{
p[cas1++]=p[i];
}
}
Graham(n);
for(i=0; i<=top; i++)
{
for(j=i+1; j<=top; j++)
{
if(stk[i].x == stk[j].x && stk[i].y == stk[j].y && stk[i].v == stk[j].v)
{
stk[i].x=stk[j].x=100000;
stk[i].y=stk[j].y=100000;
stk[i].v=stk[j].v=100000;
}
}
}
for(i=0; i<=top; i++)
{
for(j=0; j<n; j++)
{
if(stk[i].x == tmp[j].x && stk[i].y == tmp[j].y && stk[i].v == tmp[j].v)
ss[j]=1;
}
}
printf("Case #%d: ",mark++);
for(i=0; i<n; i++)
{
printf("%d",ss[i]);
}
printf("\n");
}
return 0;
}