POJ 2424 Flo ' s Restaurant simulation

Source: Internet
Author: User

Flo ' s Restaurant
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 2923 Accepted: 916

Description

Sick and tired of pushing paper in the dreary bleary-eyed world of finance, Flo ditched she desk job and built her own res Taurant.

In the small restaurant, there is several two-seat tables, four-seat tables and six-seat tables. A single diner or a group of diners should is arranged to a two-seat table, a group of three or four diners should is Arranged to a four-seat table, and a group of five or six diners should is arranged to a six-seat table.

Flo ' s restaurant serves delicious food, and many people like to eat here. Every day lunch time comes, the restaurant are usually full of diners. If there is no suitable table for a new coming group of diners, they has to wait until some suitable table was free and th ere isn ' t an earlier arrival group waiting for the same kind of tables. Kind Flo would tell them how long they would get their seat, and if it's longer than half an hour, they would leave for Anoth ER restaurant.

Now given the list of coming diners in a day, please calculate how to many diners take their food in Flo ' s restaurant. Assume it takes half an hour for every diner from taking a seat to leaving the restaurant.

Input

There is several test cases. The first line of all case contains there positive integers separated by blanks, A, B and C (A, B, C >0, a + B + C &lt Which is the number of two-seat tables, the number of four-seat tables and the number of six-seat tables respect Ively. From the second line, there are a list of coming groups of diners, each line of which contains the integers, T and N (0 &lt ; N <= 6), representing the arrival time and the number of the diners of each group. The arrival time T is denoted by hh:mm, and fixed between-22:00 (the restaurant closes at 23:00). The list is sorted by the arrival time of each group in an ascending order, and your may assume that no groups arrive at th E same time. Each test case was ended by a line of "#".

A test case with a = B = C = 0 ends the input, and should not to be processed.

Output

For each test case, you should output an integer, the total number of diners who take their food in Flo's restaurant, in a Separated line.

Sample Input

1 1 110:40 110:50 211:00 4#1 1 110:40 110:50 211:00 2#1 2 110:30 110:40 310:50 211:00 111:20 5#0 0 0

Sample Output

7312

The main idea: a restaurant has a two-person table, b four-person table, C six People table, if a group of people to eat, if the corresponding table (1, 2 people for two tables, and so on) full of words, if found to wait more than 30 minutes to go,
Let's say that everyone in the table eats for 30 minutes and asks how many people the restaurant will eventually entertain.


If there is only one table that is right), it seems that the future can not be taken for granted Ah! The idea of this problem is to create an array to record the departure time for each table, and then compare the queues with the earliest departure time, where a small trick is
If all tables are empty when the guest arrives, set the arrival time to the earliest table entry, as indicated in the code note.

Attached code:
  
#include <iostream>#include<cstdio>#include<cstring>#include<string>#include<algorithm>using namespacestd;intMain () {intA, B, C; intx[101]; inty[101]; intz[101];//freopen ("In.txt", "R", stdin);     while(Cin >> a >> b >>c) {if(!a &&!b &&!c) Break; memset (x,0,sizeof(x)); memset (Y,0,sizeof(y)); Memset (Z,0,sizeof(z)); strings; intsum =0;  while(Cin >> s && s! ="#" ) {            intN; intTime = ((s[0] -'0') *Ten+ s[1] -'0'-8) * -+ (s[3] -'0') *Ten+ s[4] -'0'; CIN>>N; Switch(n) { Case 1:                 Case 2: {sort (x, x+A);//X records the time of arrival of all guests of the same numbered table, X[0] for the earliest table .                    if(x[0]-Time <= -) {//wait no longer than 30 minutes to queueSum + =N; if(x[0] < time) x[0] = time;//If all tables are empty when the guest arrives, set the arrival time to the earliest table entry timex[0] += -;//The earliest table out time deposit x[0]                    }                     Break; }                 Case 3:                 Case 4: {sort (y, y+b); if(y[0]-Time <= -) {sum+=N; if(y[0] < time) y[0] =Time ; y[0] += -; }                     Break; }                 Case 5:                 Case 6: {sort (z, z+c); if(z[0]-Time <= -) {sum+=N; if(z[0] < time) z[0] =Time ; z[0] += -; }                     Break; }                default:                     Break; }} cout<< sum <<Endl; }    return 0;}
View Code

I still owe practice ah, efficiency or not high AH! Come on!

POJ 2424 Flo ' s Restaurant simulation

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.