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 TLE???? Help

Posted by BJ05_1096 at 2007-08-15 17:02:19 on Problem 3282
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct p
{
	int th;
	char ps[7];
}car[50];

int main()
{
	int t,i,j,len,m;
	scanf("%d",&t);
	while(t--)
	{
		//memset(k,0,sizeof(k));
		int con = 0,lans = 0,rans = 0,ans = 0;
		scanf("%d%d",&len,&m);
		for(i = 0; i < m; i++)
			scanf("%d%s",&car[i].th,car[i].ps);
		for(j = 0; j < m; j++)
	//	j = 0;
	//	while(j < m)
		{
			for(i = j; i < m; i++)
			{
				if(!strcmp(car[i].ps,car[j].ps))
				{
					con += car[i].th;
					if(con > len*100)
					{
						if(!strcmp(car[j].ps,"left")) lans++;
						else rans++;
             	//		printf("lans=%d rans=%d len = %d\n",lans,rans,car[j].th);
						j=i-1;
						con = 0;
						i = m;
					}
					else if(i == m-1)
					{
						if(!strcmp(car[j].ps,"left")) lans++;
						else rans++;
      //       			printf("lans=%d rans=%d len = %d\n",lans,rans,car[j].th);
						j=i;
					}
				}
				else
				{
					if(!strcmp(car[j].ps,"left")) lans++;
					else rans++;
     //      			printf("lans=%d rans=%d len = %d\n",lans,rans,car[j].th);
					j = i-1;
					con = 0;
					i = m;
				}
			}
		}
	//		printf("lans=%d rans=%d\n",lans,rans);
			ans = (2*lans - 1 > 2*rans) ? 2*lans-1:2*rans;
			printf("%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