HDU 4946 Area of Mushroom 凸包

Area of Mushroom

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 85    Accepted Submission(s): 10


Problem Description
Teacher Mai has a kingdom with the infinite area.

He has n students guarding the kingdom.

The i-th student stands at the position (x i,y i), and his walking speed is v i.

If a point can be reached by a student, and the time this student walking to this point is  strictly less than other students, this point is in the charge of this student.

For every student, Teacher Mai wants to know if the area in the charge of him is infinite.
 

Input
There are multiple test cases, terminated by a line "0".

For each test case, the first line contains one integer n(1<=n<=500).

In following n lines, each line contains three integers x i,y i,v i(0<=|x i|,|y i|,v i<=10^4).
 

Output
For each case, output "Case #k: s", where k is the case number counting from 1, and s is a string consisting of n character. If the area in the charge of the i-th student isn't infinite, the i-th character is "0", else it's "1".
 

Sample Input
  
  
3 0 0 3 1 1 2 2 2 1 0
 

Sample Output
  
  
Case #1: 100
 

Source
 


算下凸包,和凸包边界共线的点也要算进去,然后算凸包的时候要排除掉重复点,不然会把中间点也算进去


#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>

using namespace std;

#define PB push_back
#define MP make_pair
#define CLR(vis) memset(vis,0,sizeof(vis))
#define MST(vis,pos) memset(vis,pos,sizeof(vis))
#define MAX3(a,b,c) max(a,max(b,c))
#define MAX4(a,b,c,d) max(max(a,b),max(c,d))
#define MIN3(a,b,c) min(a,min(b,c))
#define MIN4(a,b,c,d) min(min(a,b),min(c,d))
#define PI acos(-1.0)
#define INF 0x7FFFFFFF
#define LINF 1000000000000000000LL
#define eps 1e-8

typedef long long ll;
typedef unsigned long long ull;

typedef double PointType;

struct point{
    PointType x,y;
    point(PointType x=0,PointType y=0):x(x),y(y) {}
};

typedef point Vector ;

int dcmp(double x){
    if(fabs(x) < eps) return 0;else return x<0 ?-1:1;
}

Vector operator + (Vector A , Vector B){
    return Vector(A.x + B.x , A.y + B.y);
}

Vector operator - (point A , point B){
    return Vector(A.x - B.x , A.y - B.y);
}

Vector operator * (Vector A , double p){
    return Vector(A.x * p, A.y * p);
}

Vector operator / (Vector A , double p){
    return Vector(A.x / p, A.y / p);
}

bool operator < (const point& a, const point& b){
    return a.x<b.x||(a.x==b.x && a.y<b.y);
}

bool operator == (const point& a, const point& b){
    return dcmp(a.x-b.x) == 0 && dcmp(a.y-b.y) == 0;
}



double Dot(Vector A , Vector B){
    return A.x*B.x+A.y*B.y;
}

double Length(Vector A){
    return sqrt(Dot(A,A));
}

double Cross(Vector A , Vector B){
    return A.x*B.y - A.y*B.x;
}

double Angle(Vector A , Vector B){
    return acos(Dot(A, B) / Length(A) / Length(B));
}

struct node{
    point a;
    int v;
    int id;
};

node e[5555],t[5555],ans[5555],tt[555];

int cmp(node a,node b)
{
    return a.v>b.v;
}

int cmp1(node a,node b)
{
    if(a.a.x!=b.a.x)
        return a.a.x<b.a.x;
    else
        return a.a.y<b.a.y;
}

int Convex_hull(node* p,int n,node* ch)
{
    sort(p,p+n,cmp1);
    int m=0;
    for(int i=0;i<n;i++)
    {
        while(m>1 && Cross(ch[m-1].a-ch[m-2].a,p[i].a-ch[m-2].a)<0)
            m--;
        ch[m++]=p[i];
    }
    int k=m;
    for(int i=n-2;i>=0;i--)
    {
        while(m>k && Cross(ch[m-1].a-ch[m-2].a,p[i].a-ch[m-2].a)<0)
            m--;
        ch[m++]=p[i];
    }
    if(n>1)
        m--;
    return m;
}

double Convex_polygon_area(node* p, int n){
    double area = 0;
    for(int i = 1;i < n-1; i++)
        area +=Cross(p[i].a-p[0].a,p[i+1].a-p[0].a);
    return area/2;
}
 
int n;


int main()
{
    int cas=1;
    int vis[555];
    map< pair<int,int> ,int> p;
    while(cin>>n)
    {
        if(n==0) break;
        CLR(ans),CLR(e),CLR(t),CLR(tt);
        int max_v=-1;
        for(int i=0;i<n;i++)
        {
            scanf("%lf%lf%d",&e[i].a.x,&e[i].a.y,&e[i].v);
            max_v=max(max_v,e[i].v);
            e[i].id=i;
        }

        if(max_v==0)
        {
            printf("Case #%d: ",cas++);
            for(int i=0;i<n;i++)
            {
                printf("0");
            }
            cout<<endl;
            continue;
        }

        map< pair<int ,int> ,int > s;
        int g=0;
        for(int i=0;i<n;i++)
        {
            if(e[i].v==max_v)
                t[g++]=e[i];
        }
        s.clear();
        int gg=0;
        for(int i=0;i<g;i++)
        {
            int u=t[i].a.x,v=t[i].a.y;
            if(s[MP(u,v)]==0)
            {
                tt[gg++]=t[i];
                s[MP(u,v)]++;
            }
        }



        int res=Convex_hull(tt,gg,ans);
        //cout<<res<<endl;
        //for(int i=0;i<res;i++)
          // cout<<ans[i].a.x<<" "<<ans[i].a.y<<endl;
        double sum=Convex_polygon_area(ans,res);
       // cout<<sum<<endl;
        if(sum==0)
        {
            p.clear();
            CLR(vis);
            for(int i=0;i<g;i++)
           {
              p[MP(t[i].a.x,t[i].a.y)]++;
           }
           for(int i=0;i<res;i++)
           {
              vis[ans[i].id]=1;
           }

            printf("Case #%d: ",cas++);
            for(int i=0;i<n;i++)
            {
                if(vis[i]==0)
                   printf("0");
               else
               {
                  int u=e[i].a.x,v=e[i].a.y;
                  if(p[MP(u,v)]>1)
                    printf("0");
                  else
                    printf("1");
                }
            }
            cout<<endl;
            continue;
        }
        CLR(vis);
        p.clear();
        for(int i=0;i<g;i++)
        {
            p[MP(t[i].a.x,t[i].a.y)]++;
        }
        for(int i=0;i<res;i++)
        {
            vis[ans[i].id]=1;
        }
        printf("Case #%d: ",cas++);
        for(int i=0;i<n;i++)
        {
            if(vis[i]==0)
                printf("0");
            else
            {
                int u=e[i].a.x,v=e[i].a.y;
                if(p[MP(u,v)]>1)
                    printf("0");
                else
                    printf("1");
            }
        }
        cout<<endl;


    }
}

/*
9
0 0 1
0 0 1
4 0 1
4 0 1
0 4 1
0 4 1
4 4 1
2 2 1
4 4 1
1
2 2 7
Case #1: 000000000
*/


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值