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

why WA???代码不长

Posted by BJ051155 at 2007-05-10 21:53:03 on Problem 1899
#include <stdio.h>
int r[100],l[100],u[100],d[100];

bool overlap(short i,short j)
{
	if(r[i]==0&&l[i]==0&&u[i]==0&&d[i]==0)
		return 0;
	if(r[j]==0&&l[j]==0&&u[j]==0&&d[j]==0)
		return 0;
	if(r[i]<=r[j]&&r[i]>=l[j]&&!(d[i]>u[j]||u[i]<d[j]))
		return 1;
	if(r[j]<=r[i]&&r[j]>=l[i]&&!(d[j]>u[i]||u[j]<d[i]))
		return 1;
	return 0;
}

int main(int argc, char* argv[])
{
	int x,y,xi[100],yi[100],ri[100];
	short n;
	scanf("%d%d%d",&x,&y,&n);
	for(short i=0;i<n;i++)
	{
		scanf("%d%d%d",&xi[i],&yi[i],&ri[i]);
		r[i]=xi[i]+ri[i];
		l[i]=xi[i]-ri[i];
		u[i]=yi[i]+ri[i];
		d[i]=yi[i]-ri[i];
	}
	bool sign=1;
	while(sign)
	{
		sign=0;
		for(i=1;i<n;i++)
			if(overlap(i-1,i))
			{
				sign=1;
				if(r[i]<r[i-1])
					r[i]=r[i-1];
				if(u[i]<u[i-1])
					u[i]=u[i-1];
				if(l[i]>l[i-1])
					l[i]=l[i-1];
				if(d[i]>d[i-1])
					d[i]=d[i-1];
				r[i-1]=l[i-1]=u[i-1]=d[i-1]=0;
			}
	}
	int total=0;
	for(i=0;i<n;i++)
		total+=(r[i]-l[i])*(u[i]-d[i]);//printf("%d %d\n",(r[i]-l[i]),(u[i]-d[i]));}
	printf("%d\n",x*y-total);
	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