程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> POJ 3282 Ferry Loading IV(模擬)

POJ 3282 Ferry Loading IV(模擬)

編輯:C++入門知識

POJ 3282 Ferry Loading IV(模擬)


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


  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved