设为首页 加入收藏

TOP

POJ 3282 Ferry Loading IV(模拟)
2015-07-20 17:54:40 来源: 作者: 【 】 浏览:2
Tags:POJ 3282 Ferry Loading 模拟

Description

Before bridges were common, ferries were used to transport cars across rivers. River ferries, unlike their larger cousins, run on a guide line and are powered by the river's current. Cars drive onto the ferry from one end, the ferry crosses the river, and the cars exit from the other end of the ferry.

There is an l-meter-long ferry that crosses the river. A car may arrive at either river bank to be transported by the ferry to the opposite bank. The ferry travels continuously back and forth between the banks so long as it is carrying a car or there is at least one car waiting at either bank. Whenever the ferry arrives at one of the banks, it unloads its cargo and loads up cars that are waiting to cross as long as they fit on its deck. The cars are loaded in the order of their arrival; ferry's deck accommodates only one lane of cars. The ferry is initially on the left bank where it broke and it took quite some time to fix it. In the meantime, lines of cars formed on both banks that await to cross the river.

Input

The first line of input contains c, the number of test cases. Each test case begins with l, m. m lines follow describing the cars that arrive in this order to be transported. Each line gives the length of a car (in centimeters), and the bank at which the car arrives ("left" or "right").

Output

For each test case, output one line giving the number of times the ferry has to cross the river in order to serve all waiting cars.

Sample Input

4
20 4
380 left
720 left
1340 right
1040 left
15 4 
380 left
720 left
1340 right
1040 left
15 4 
380 left
720 left
1340 left
1040 left
15 4 
380 right
720 right
1340 right
1040 right

Sample Output

3
3
5
6

Source




坑爹的题,题目读半天;


题意:船刚开始在左边,刚开始给出船的长度,单位是米,后来给出左右货物的来到顺序和货物的长度,单位居然是厘米 !!!,吧左边货物运到右边,右边的运到左边,还有题目说货物必须先来的先运,我居然以为必须严格的先后顺序,例如船 100 3 50 left 50 rigt 50 left 我以为必须把右边的那个运完再运左边第二个50,搞得错4发,其实不是的 可以左边两个一起(和小于船的长度),再运右边⊙?⊙b汗,后来还有10分钟的时候终于a了,哎语文和英语不行啊。。。。。。




#include
  
   
#include
   
     #include
    
      #include
     
       #include
      
        #include
       
         using namespace std; #define N 100005 int ll[N],rr[N]; //分别存左边和右边 int main() { int t,i,n,len; scanf("%d",&t); while(t--) { scanf("%d%d",&len,&n); len*=100;//米转化成厘米 if(n==0) { printf("0\n"); continue; } char c[10]; int x; int xx,yy; xx=yy=0; int ans=0; for(i=0;i
        
         


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇POJ 1269 Intersecting Lines(判.. 下一篇C++ 我想这样用(二)

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: