HDU 4946 area of mushroom

Source: Internet
Author: User

Question:

Given n people on a two-dimensional plane

Coordinates and moving speed of each person v

For a certain point, only X can arrive first (that is, no one can arrive at this point or at the same time than X)

This point is called X. If someone can occupy an infinite area, 1 is output; otherwise, 0 is output.

 

Ideas:

1. Sort all vertices by speed, and remove vertices that are not the maximum speed.

The remaining points may occupy an infinite area.

2. Create a convex hull for the vertex with the highest speed. Only the vertices on the convex hull can occupy an infinite number.

If there are multiple people in a single position, these people cannot possess an infinite number.

The points on the top of the convex hull must be retained.

 

# Easy to troubleshoot:

1. the vertices on the sides of the convex hull should be kept in a collinearity. It is best to use horizontal sorting (before constructing the convex hull)

2. for de-emphasis, the convex hull must be constructed.

 

Wa: focus before constructing a convex hull

#include<stdio.h>#include<algorithm>#include<fstream>#include<string.h>#include<iostream>using namespace std;const int MAX=550;struct point{    int x;    int y;    int v;    int i;}p[MAX],Ini[MAX],res[MAX];int ans[MAX];bool cmp(point A,point B){    if(A.y==B.y)return A.x<B.x;    return A.y<B.y;}bool cmp1(point A,point B){    if(A.v>B.v)return true;    if(A.v==B.v)    {        if(A.x<B.x)return true;        if(A.x==B.x&&A.y<B.y)return true;    }    return false;}int cross(point A,point B,point C){    return (B.x-A.x)*(C.y-A.y)-(C.x-A.x)*(B.y-A.y);}int Graham(point *p,int n){    //if (n<3)return n;    sort(p,p+n,cmp);    int i;    int top=0;    for(i=0;i<n;i++)    {        while(top>=2&&cross(res[top-2],res[top-1],p[i])<0)            top--;        res[top++]=p[i];    }    int t=top+1;    for(i=n-2;i>=0;i--)    {        while(top>=t&&cross(res[top-2],res[top-1],p[i])<0)            top--;        res[top++]=p[i];    }    /*for(i=0;i<top;i++)        printf("%d %d\n",res[i].x,res[i].y);*/    return top;}int main(){    int n;    int i,j;    //ifstream cin("A.txt");    int __case=0;    while(cin>>n&&n)    {        for(i=0;i<n;i++)        {            cin>>Ini[i].x>>Ini[i].y>>Ini[i].v;            Ini[i].i=i;        }        sort(Ini,Ini+n,cmp1);            //cout<<Ini[i-1].x<<Ini[i-1].y;        int tmp=0;        for(i=0;i<n;i++)        {            if(Ini[0].v==Ini[i].v)tmp++;            else break;        }        point po;        for(i=0,j=0;i<tmp;)        {            po=Ini[i];            if(i<tmp-1&&Ini[i+1].x==Ini[i].x&&Ini[i+1].y==Ini[i].y)            {                while(i<tmp-1&&Ini[i+1].x==Ini[i].x&&Ini[i+1].y==Ini[i].y)                    i++;            }            else            {                p[j++]=po;            }            i++;        }        printf("Case #%d: ",++__case);        int m=Graham(p,j);        memset(ans,0,sizeof(ans));        for(i=0;i<m;i++)        {            //printf("%d %d %d",res[i].x,res[i].y,res[i].v);            if(res[i].v>0)            {                ans[res[i].i]=1;            }        }        for(i=0;i<n;i++)            printf("%d",ans[i]);        printf("\n");    }    return 0;}
View code

 

AC:

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.