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

求各位大侠帮忙看看是哪里错了,WA到吐。。T ^ T

Posted by 2011339960140 at 2013-03-15 12:33:34 on Problem 2424
#include<cstdio>
#include<cstring>
#include<queue>
#include<algorithm>
using namespace std;

struct Time
{
	int t;
	bool operator < (const Time &temp) const
	{
		return t>temp.t;
	}
} cnt;

priority_queue<Time> q[3];

int num[3];

int limit[3];

char str[11];

int main()
{
	while(~scanf("%d%d%d",&limit[0],&limit[1],&limit[2]))
	{
		if(limit[0]+limit[1]+limit[2]==0)
			break;
			
		for(int i=0;i<3;i++)
			while(!q[i].empty())
				q[i].pop();
				
		int ans=0;
		num[0]=num[1]=num[2]=0;
		while(1)
		{
			
			scanf("%s",str);
			if(str[0]=='#')
			{
				printf("%d\n",ans);
				break;
			}
			int p;
			scanf("%d",&p);
			
			int flag=0;
			int h=0,m=0;
			for(int i=0;str[i]!='\0';i++)
			{
				if(str[i]==':')
				{
					flag=1;
					continue;
				}
				if(!flag)
					h=h*10+str[i]-'0';
				else m=m*10+str[i]-'0';
			}
			cnt.t=h*60+m;

			int pos ;
			if(p<=2) pos=0;
			else if(p<=4) pos=1;
			else pos=2;
			
			if(q[pos].empty())
			{
				cnt.t+=30;
				q[pos].push(cnt); 
				num[pos]++;
				ans+=p;
				continue;
			}
			while(!q[pos].empty())
			{
				if(q[pos].top().t<=cnt.t)
				{
					num[pos]--;
					
					q[pos].pop();
				}
				else break;
			}
			if(num[pos]<limit[pos])
			{
				cnt.t+=30;
				q[pos].push(cnt);
				num[pos]++;
				ans+=p;
			}
			else if(num[pos]==limit[pos])
			{
				int t=q[pos].top().t;
				if(t-cnt.t<=30)
				{
					ans+=p;
					cnt.t=max(cnt.t,t)+30;
					q[pos].push(cnt);
					num[pos]++;
				}
			}
			//printf("ans = %d\n",ans);
		}
	}
	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