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 200609020331 at 2008-11-15 12:54:54 on Problem 3282
怎么老是RA啊,但是把数组开大一位又说我RE!不知道哪有问题啊,我是用队列做的!附加代码
#include<iostream>
using namespace std;
#define N 100000000
int main()
{
	int l,m,i,front1,rear1,front2,rear2;
	int cases,accouts,sum1,sum2;
	int lque[N],rque[N];
	int num;
	char location[10];
	scanf("%d",&cases);
	while(cases>0)
	{
		accouts=0;
		front1=rear1=front2=rear2=0;
		scanf("%d %d",&l,&m);
		l=l*100;
		for(i=0;i<m;i++)
		{
			scanf("%d %s",&num,location);
			if(strcmp(location,"left")==0)
			{
				lque[rear1]=num;
				rear1++;
			}
			else if(strcmp(location,"right")==0)
			{
				rque[rear2]=num;
				rear2++;
			}
		}
		if(rear1==0 && rear2!=0)
		{
			while(front2!=rear2)
			{
				sum2=0;
				accouts++;
				while(front2!=rear2)
				{
					sum2+=rque[front2];
					front2++;
					if(sum2>l)
					{
						accouts++;
						front2--;
						break;
					}
					else if(sum2==l)
					{
						accouts++;
						break;
					}
					else if(sum2<l && front2==rear2)
						accouts++;
				}
			}
		}
		else if(rear2==0 && rear1!=0)
		{	
			while(front1!=rear1)
			{
				sum1=0;
				while(front1!=rear1)
				{
					sum1+=lque[front1];
					front1++;
					if(sum1>l)
					{
						accouts++;
						front1--;
						break;
					}
					else if(sum1==l)
					{
						accouts++;
						break;
					}
					else if(sum1<l && front1==rear1)
						accouts++;
				}
				accouts++;
			}
			accouts--;
		}	
		else
		{
			while(front1!=rear1 || front2!=rear2)
			{
				sum1=sum2=0;
				while(front1!=rear1)
				{
					sum1+=lque[front1];
					front1++;
					if(sum1>l)
					{
						accouts++;
						front1--;
						break;
					}
					else if(sum1==l)
					{
						accouts++;
						break;
					}
					else if(sum1<l && front1==rear1)
						accouts++;
				}
				while(front2!=rear2)
				{
					sum2+=rque[front2];
					front2++;
					if(sum2>l)
					{
						accouts++;
						front2--;
						break;
					}
					else if(sum2==l)
					{
						accouts++;
						break;
					}
					else if(sum2<l && front2==rear2)
						accouts++;
				}
			}
		}
		cout<<accouts<<endl;
		cases--;
	}
	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