Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

1696 求测试数据,想了两天就是过不了,晕啊。。。。

Posted by chuyuedefengge at 2011-08-11 11:12:29 and last updated at 2011-08-11 11:14:04
#include <iostream>
#include <algorithm>
using namespace std;
const int maxn=55;

int used[maxn];

struct point{
	int  x,y;
	int pos;
	friend bool operator <(const point p1,const point p2){
		return p1.y<p2.y || p1.y==p2.y&&p1.x<p2.x;
	}
};

struct polygon{
	point p[maxn];
	int num;
}poly,convex;

int  cross(const point p1,const point p2,const point p3){
	return (p1.x-p3.x)*(p2.y-p3.y)-(p1.y-p3.y)*(p2.x-p3.x);
}

int  Graham_scan(polygon& pt,polygon& convex){
	int a,i,n=pt.num,top=0;
	sort(pt.p,pt.p+n);
	convex.p[0]=pt.p[0];
	top++;
	used[pt.p[0].pos]=0;
	while(top<n){
		for(i=1;i<n;i++){
			if(used[pt.p[i].pos]){
				while(i>1&&cross(convex.p[top-2],convex.p[top-1],pt.p[i])<0){	
					top--;
					used[convex.p[top].pos]=1;
				}				
				convex.p[top++]=pt.p[i];
				used[pt.p[i].pos]=0;
			}
		}
		a=top+1;
		for(i=n-2;i>=0;i--){
			if(used[pt.p[i].pos]){	
				while(a<=top&&cross(convex.p[top-2],convex.p[top-1],pt.p[i])<0){
					top--;
					used[convex.p[top].pos]=1;
				}
				convex.p[top++]=pt.p[i];
				used[pt.p[i].pos]=0;
			}
		}
	}
	convex.num=n;
	return 0;
}

int main()
{
	int a,b,t;
	scanf("%d",&t);
	while(t--){
		scanf("%d",&a);
		poly.num=0;
		for(b=0;b<a;b++){
			scanf("%d%d%d",&poly.p[b].pos,&poly.p[b].x,&poly.p[b].y);
			used[poly.p[b].pos]=1;			
		}
		poly.num=a;
		Graham_scan(poly,convex);
		printf("%d ",a);
		a--;
		for(b=0;b<a;b++){
			printf("%d ",convex.p[b].pos);
		}
		printf("%d\n",convex.p[a].pos);
	}
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator