Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
Why TLE???? Help#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator