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

请前辈指点!!

Posted by jiangfan87 at 2008-03-22 15:35:33 on Problem 3327
In Reply To:Re:终于AC,眼泪都哭干了。RE/TLE的同志们注意了: Posted by:marbles at 2007-08-08 00:59:03
我没搞懂我的代码是怎样RE,请高手们指点哈——
代码:
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
struct node
{
	int w;
	int d;
};
bool cmp(node a,node b)
{
	return a.w*a.d<b.w*b.d;
};
int main()
{
	int n,w,d,p,s,i,w1,w2,d1,d2,m,j;
	node cake[120];
	scanf("%d%d%d",&n,&w,&d);
	while(n||w||d)
	{
		memset(cake,0,sizeof(cake));
		cake[1].w=w;cake[1].d=d;
			for(i=1;i<=n;i++)
			{
				scanf("%d%d",&p,&s);
				m=s%((cake[p].d+cake[p].w)*2);
				if(m<cake[p].w)
				{
					w1=m;w2=cake[p].w-w1;
					swap(w1,w2);
					d2=d1=cake[p].d;
				}
				else if(m<cake[p].w+cake[p].d)
				{
					d1=m-cake[p].w;
					d2=cake[p].d-d1;
					swap(d1,d2);
					w2=w1=cake[p].w;
				}
				else if(m<cake[p].w*2+cake[p].d)
				{
					w1=cake[p].w*2+cake[p].d-m;
					w2=cake[p].w-w1;
					swap(w1,w2);
					d1=d2=cake[p].d;
				}
				else
				{
					d1=2*(cake[p].w+cake[p].d)-m;
					d2=cake[p].d-d1;
					swap(d1,d2);					
					w1=w2=cake[p].w;
				}
				for(j=p;j<i;j++)
				{
					cake[j].w=cake[j+1].w;
					cake[j].d=cake[j+1].d;
				}
				cake[i].w=w1;
				cake[i].d=d1;
				cake[i+1].w=w2;
				cake[i+1].d=d2;
			}
			sort(cake+1,cake+n+2,cmp);
			for(i=1;i<=n+1;i++)
				printf("%d ",cake[i].w*cake[i].d);
			printf("\n");
		scanf("%d%d%d",&n,&w,&d);
	}
	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