模拟题
/* 模拟 注意:相同一边的车有先后顺序! */ #include<stdio.h> #include<string.h> #include<stdlib.h> #include<algorithm> #include<iostream> #include<queue> #include<map> #include<stack> #include<set> #include<math.h> using namespace std; typedef long long int64; //typedef __int64 int64; typedef pair<int64,int64> PII; #define MP(a,b) make_pair((a),(b)) const int maxn = 100000; const int inf = 0x7fffffff; const double pi=acos(-1.0); const double eps = 1e-8; struct Node{ int len; int id; }a[ maxn ]; bool Judge( int n ){ bool f = true; for( int i=n;i>=1;i-- ){ if( a[i].id!=0 ){ f = false; break; } } if( f==true ) return true; else return false; } int main(){ int T; //freopen("in.txt","r",stdin); //freopen("out.txt","w",stdout); scanf("%d",&T); while( T-- ){ int LL,n; scanf("%d%d",&LL,&n); LL *= 100; char t[ 10 ]; for( int i=1;i<=n;i++ ){ scanf("%d %s",&a[i].len,t); if( t[0]=='l' ) a[i].id = -1; else a[i].id = 1; } int ans = 0; int cur = -1; int L,R; L = R = 1; while( 1 ){ if( Judge( n )==true ) break; //judge cur = -1; int sum = 0; for( ;L<=n;L++ ){ if( a[L].id!=cur ) continue; if( sum+a[L].len<=LL ){ sum += a[L].len; a[ L ].id = 0; } else break; } ans ++; if( Judge( n )==true ) break; //left sum = 0; cur = 1; for( ;R<=n;R++ ){ if( a[R].id!=cur ) continue; if( sum+a[R].len<=LL ){ sum += a[R].len; a[ R ].id = 0; } else break; } ans++; //right } printf("%d ",ans); } return 0; }