#include<iostream>
#include<cstdio>
#include<stack>
#include<queue>
#include<cstring>
using namespace std ;
int main()
{
string jak ;
int len ;
queue <double> left ;
queue <double> right ;
int test ;
cin>>test ;
while(test--)
{
int len , m, flag ;
double sum =0 ,r,t;
cin>>len>>m ;
while(m--)
{
cin>>r>>jak ;
if(jak=="left")
left.push(r) ;
else if(jak=="right")
right.push(r) ;
}
int count =0 ;
while(1)
{
sum =0 ;
flag =0 ;
while(!left.empty())
{
r= left.front() ;
t = r/100.00 ;
flag =1 ;
if(sum+t<=len)
{
sum = sum + t ;
left.pop() ;
}
else
break ;
}
count++ ;
if(left.empty()&&right.empty())
break;
sum =0 ;
while(!right.empty())
{
r = right.front() ;
t = r/100.00 ;
flag =1 ;
if(sum+t<=len)
{
sum = sum + t ;
right.pop() ;
}
else
break ;
}
count++ ;
if(left.empty()&&right.empty())
break;
}
printf("%d\n",count) ;
}
return 0 ;
}
#include<cstdio>
#include<stack>
#include<queue>
#include<cstring>
using namespace std ;
int main()
{
string jak ;
int len ;
queue <double> left ;
queue <double> right ;
int test ;
cin>>test ;
while(test--)
{
int len , m, flag ;
double sum =0 ,r,t;
cin>>len>>m ;
while(m--)
{
cin>>r>>jak ;
if(jak=="left")
left.push(r) ;
else if(jak=="right")
right.push(r) ;
}
int count =0 ;
while(1)
{
sum =0 ;
flag =0 ;
while(!left.empty())
{
r= left.front() ;
t = r/100.00 ;
flag =1 ;
if(sum+t<=len)
{
sum = sum + t ;
left.pop() ;
}
else
break ;
}
count++ ;
if(left.empty()&&right.empty())
break;
sum =0 ;
while(!right.empty())
{
r = right.front() ;
t = r/100.00 ;
flag =1 ;
if(sum+t<=len)
{
sum = sum + t ;
right.pop() ;
}
else
break ;
}
count++ ;
if(left.empty()&&right.empty())
break;
}
printf("%d\n",count) ;
}
return 0 ;
}
No comments:
Post a Comment