Hdu4072working at the Restaurant (analog)

Source: Internet
Author: User

working at the Restaurant

Description

Last night, Tom went in a date with a really nice girl. However, he forgot to take his credits card with him and he had no cash in his wallet, so he ended up working at the Restau Rant to pay for the bill. His task was to take plates from the waiter if he comes from the tables, and pass them along when the Diswasher requests them. It is very important for the plates to being washed in the same order as they was brought from the tables, as otherwise it co Uld take too long before a plate are washed, and leftover food might get stuck. Trying to hold all the plates in he hands is probably not a great idea, so Tom puts them on a table as soon as the waiter Hands them-him, and picks them up from the table again when the time comes to pass them along to the dishwasher. There is space for only piles of plates on the table, which'll be referred to as pile 1 and pile 2. There is a one table Tom can use. Tom won last year's Swerc, so he's certainly capable of optimizing for EfficienCy. You had to output a transcript of one possible-in which Tom might decide to organize the plates on the table during T He process, given the sequence of plates and requests he receives. 

Input

The input has several test cases. Begins with a line containing a number N (1 <=n <= 1), followed by N lines, which contain either DROP M or take M, where M > 0 are the number of plates to take or drop. Drop m represents that the next event is the waiter bringing m plates to Tom, so he had to drop them on the table, while T AKE m represents that the next event was Tom taking m plates from the table and passing them along on the right order. You can assume this he never receives a take m instruction when there is fewer than m plates on the table, and that the S Um M of all values of m corresponding to DROP operations does not exceed 100 000. Note that there might was plates left on Tom's table when the last request was issued, as Tom might was relieved of his duty To stay until the restaurant closes. The input ends with a line with N = 0, which must isn't be processed. 

Output

For every test case, the output would be a series of lines describing the operations to be performed with the plates. The content of each line would be one of the following:
1, drop 1 m (drop 2 m), M > 0, if Tom needs to take a plate from the waiter, drop it on top of pile 1 (pile 2), and rep Eat this operation m times in total.
2, take 1 m (take 2 m), M > 0, if Tom needs to take a plate from the top of pile 1 (pile 2), pass it along to the DISHW Asher, and repeat m times in total.
3, move 1->2 m (move 2->1 m), M > 0, if Tom needs to take a plate from the top of pile 1 (pile 2), drop it on top of pile 2 (pile 1), and repeat m times in total.
You must output at a most 6N lines, and the total number of movements of plates in your transcript (which is, the sum of the M ' s printed in your output, for all three kinds of operations), must is at the most 6M, as otherwise Tom won ' t being able to cope With all the work. Note that Tom must obey the commands in the same order as they is issued. This means the if he receives a take M command, he must perform a certain number of MOVE and take operations such that T He sum of the numbers of plates taken adds up exactly to M before performing the operations corresponding to the next comm and; And if he receives a drop m command, he must perform a number of DROP or MOVE operations for which the sum of the Nu-mber S of plates dropped adds up exactly to M before performing the operations corresponding to the next command. Of course, it is also forbidden to take plates from the waiter or pass them along to the dishwasher in the absence of the Corr-esponding order. There must be a empty line between the Outputs of Di erent cases. Any solution satisfying these conditions would be accepted.
 

Sample Input

 

Sample Output


Test instructions: When I read "Drop M", I took the plate from the waiter and put it in heap 2nd. When you read "Take M", get m plates from number 1th to the dishwasher. Test instructions required the order of the plates and the order in which they came in. This will use the "move 1->2 T" operation, transfer the T-plate from the No. 1th heap to the No. 2nd heap. Note that every time you take a plate, it starts at the top. An empty line between each of the two examples.
Idea: Simulation. Every time the heap of No. 1th is empty, all the plates of number 2nd are moved to Heap 1th, which ensures that the order will not be faulted.

<span style= "FONT-SIZE:18PX;" > #include <cstdio> #include <iostream> #include <cstring> #include <cmath> #include < string> #include <algorithm> #include <queue> #include <stack>using namespace Std;const Double PI = ACOs ( -1.0); const double e = 2.718281828459;const double EPS = 1e-8;char s[10];int main () {//freopen ("In.txt", "R", Stdi    n);    Freopen ("OUT.txt", "w", stdout);    int n;    int flag = 0;        while (Cin>>n && N) {if (!flag) flag = 1;        else printf ("\ n");        int sum1, sum2, M;        sum1 = sum2 = 0;            while (n--) {cin>>s>>m; if (s[0] = = ' D ') {<span><span class= "comment" >//encountered a drop to save the plate to heap 2nd, sum2+=m, and output "DROP" Operation </span&gt                ;<span></span></span> printf ("DROP 2%d\n", m);            Sum2 + = m;        } else {if (sum1 >= m)        {//If the number of plates remaining in the 1th heap is >= m, the direct output "take" Operation printf ("Take 1%d\n", m);                sum1 = m;                    } else {//If the remaining plate number of the 1th heap < m, first output all plates of the 1th heap if (sum1 > 0)                        {printf ("Take 1%d\n", sum1);                        M-= sum1;                    sum1 = 0;                    }//Move all plates of the No. 2nd heap to heap 1th printf ("Move 2->1%d\n", sum2);                    SUM1 = sum2;  sum2 = 0;                        Output the remaining m-value if (M > 0) {printf ("Take 1%d\n", m);                    sum1 = m; }}}}} return 0;} </span>


Hdu4072working at the Restaurant (analog)

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.