凸包

  
Area of Mushroom

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


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

数据:

9
1 1 3
1 2 3
1 3 3
2 1 3
2 2 3
2 3 3
3 1 3
3 2 3
3 3 3
5
0 1 0
1 0 1
0 1 1
1 1 1
1 1 1
6
1 5 7
5 6 7
6 6 7
4 5 7
4 4 7
5 5 7

#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stack>
#include <algorithm>
using namespace std;
struct node{
	int x,y,v,id;
}a[10010],b[10010]; 

double x1,yy;

int k;

stack<int>S;

bool cmp(node a,node b){
    double X1 = double(a.x) - x1;
    double Y1 = double(a.y) - yy;
    double X2 = double(b.x) - x1;
    double Y2 = double(b.y) - yy;
    if(X1/sqrt(X1*X1+Y1*Y1) == X2/sqrt(X2*X2+Y2*Y2)){
    	if(a.x == b.x) 
		    return a.y >= b.y;
   	    return a.x < b.x;
    }
	return X1/sqrt(X1*X1+Y1*Y1) > X2/sqrt(X2*X2+Y2*Y2);
}

int chacheng(int aa,int bb,int cc){
	if(cc == k)cc = 0;
	int x1 = b[bb].x - b[aa].x;
	int y1 = b[bb].y - b[aa].y;
	int x2 = b[cc].x - b[bb].x;
	int y2 = b[cc].y - b[bb].y;
	if(x2*y1-x1*y2<=0)return 1;
	else return 0;
}

int main(){
	int o = 0;
	int n;
	int v[10010];
    while(scanf("%d",&n),n){
    	o++;
    	
    	memset(v,0,sizeof(v));
    	
    	while(!S.empty())S.pop(); 
    	
    	int max = -1;
    	
    	int xz;
    	
    	for(int i=0;i<n;i++){
	    	scanf("%d%d%d",&a[i].x,&a[i].y,&a[i].v);
	    	if(a[i].v > max)max = a[i].v;
	    	a[i].id = i; 
	    }
    
	    if(max == 0){
    		printf("Case #%d: ",o);
    		for(int i=0;i<n;i++)printf("%d",0);
    		printf("\n");
    	}
    	 
    	else{
    		
	        k = 0;
	        xz = 0;
	        for(int i=0;i<n;i++){
    		    if(a[i].v == max){
    			    b[k].x = a[i].x;
    			    b[k].y = a[i].y;
    			    b[k].v = a[i].v;
    			    b[k].id = a[i].id;
			        if(b[k].y<b[xz].y)xz = k;
		            k++;
    	        }
            }    
	   
        yy = double(b[xz].y);
        x1 = double(b[xz].x);
        
        int t1;
    	t1=b[0].x,b[0].x=b[xz].x,b[xz].x=t1;
    	t1=b[0].y,b[0].y=b[xz].y,b[xz].y=t1;
    	t1=b[0].v,b[0].v=b[xz].v,b[xz].v=t1;
    	t1=b[0].id,b[0].id=b[xz].id,b[xz].id=t1;
    	
	    sort(b+1,b+k,cmp);
	    printf("%d\n",k);
	    
	    for(int i=0;i<k;i++)printf(",%d %d\n",b[i].x,b[i].y);
	    
	    for(int i = 0;i < k-1;i++) 
	        if(b[i].x == b[i+1].x&&b[i].y == b[i+1].y)v[i] = v[i+1] = 1;
	    for(int i=1;i<k;i++)
	        if(b[i].x == b[0].x&&b[i].y == b[0].y)v[i] = v[0] =1;
	        
	    S.push(0);
	    
		if(k>=2)S.push(1); 
	    int k1 = 2;
	    
    	while(k1<=k){
	    	int t = S.top();
	    	S.pop();
	    	int t1 = S.top();
	    	S.push(t);
	    	if(chacheng(t1,t,k1)){if(k1!=k)S.push(k1);k1++;}
	    	    else S.pop();
    	}
    	
    	int p = 0;
    	int flag = 0;
    	int c[10010];
    	
    	while(!S.empty()){c[p++] = S.top();S.pop();}
    	
    	printf("Case #%d: ",o);
    	for(int i=0;i<n;i++){
	    	for(int j = 0;j<p;j++)
    	        if(i == b[c[j]].id&&v[c[j]]==0){printf("%d",1);flag = 1;break;}
            if(!flag)printf("%d",0);
            flag = 0;
	    }	
    	printf("\n");
	    }
    }
} 


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值