POJ 3282 Ferry Loading IV (simulation)

Source: Internet
Author: User

POJ 3282 Ferry Loading IV (simulation)

Description

Before bridges were common, ferries were used to transport cars into SS 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 isL-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 containsC, The number of test cases. Each test case beginsL, m.MLines 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

420 4380 left720 left1340 right1040 left15 4 380 left720 left1340 right1040 left15 4 380 left720 left1340 left1040 left15 4 380 right720 right1340 right1040 right

Sample Output

3356

Source




He has read questions for half a day;


Question: The ship is on the left at the beginning. The length of the ship is given at the beginning, in meters. Then, the order of arrival of the goods and the length of the goods are given. The unit is actually centimeter !!!, The goods on the left are shipped to the right, and the goods on the right are shipped to the left. There is also a question that the goods must be first served first. I thought it must be strictly ordered, for example, ship 100 3 50 left 50 rigt 50 left I thought we had to run the right one and then run the second 50 on the left. I got 4 wrong hair, in fact, it is not possible to have two sides on the left (less than the length of the ship), and then run the sweat on the right, then there will be 10 minutes to finally, ah, Chinese and English are not good ......




# Include
 
  
# Include
  
   
# Include
   
    
# Include
    
     
# Include
     
      
Using namespace std; # define N records 5int ll [N], rr [N]; // save int main () {int t, I, n, len on the left and right respectively; scanf ("% d", & t); while (t --) {scanf ("% d", & len, & n); len * = 100; // convert the meter to centimeter 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
      
       


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.