[ACM] HDU 4884 TIANKENG’s rice shop (模拟)

TIANKENG’s rice shop

Problem Description

TIANKENG managers a pan fried rice shop. There are n kinds of fried rice numbered 1-n. TIANKENG will spend t time for once frying. Because the pan is so small, TIANKENG can fry k bowls of fried rice with same kind at most.
Assuming that there are m customers coming to the shop, and we know the arriving time of each customer and the brand and number of the fried rice they need. Could you tell TIANKENG the departure time of every customer respectively? Pay attention that TIANKNEG
will serve the customer who comes earlier and he will fry the rice as much as possible. Meanwhile, customers are in queue depending on their arriving time(the earlier they arrive, the more front they stand).

Input

The first line contains a positive integer T(T<=100), referring to T test cases.

For each test case, the first line has 4 positive integer n(1<=n<=1000), t(1<=t<=10), k(1<=k<=5), m(1<=m<=1000), then following m lines , each line has a time(the time format is hh:mm, 0<=hh<=23, 0<=mm<=59) and two positive integer id(1<=id<=n), num(1<=num<=10),
which means the brand number of the fried rice and the number of the fried rice the customer needs.

Pay attention that two or more customers will not come to the shop at the same time, the arriving time of the customer will be ordered by the time(from early time to late time)

Output

For each test case print m lines, each line contains a time referring to the departure time of the customer. There is a blank line between two test cases.

Sample Input

3
2 1 4 2
08:00 1 5
09:00 2 1
2 5 4 3
08:00 1 4
08:01 2 2
08:02 2 2
2 5 4 2
08:00 1 1
08:04 1 1

Sample Output

08:02
09:01

08:05
08:10
08:10

08:05
08:10

Source

BestCoder Round #2

Recommend

liuyiding

解题思路:

这道模拟题太坑了......

一共有n种炒饭,每种炒饭炒一次都花t分钟,炒一次是k份的量,每次只能炒同一种炒饭,有m个客人,给出每个客人的到来时间,以及所要炒饭的种类和数量,问每个客人的最早离开时间.

一开始第三组测试数据没看懂

n=2 t=5 k=4 m=2

08:00 1 1

08:04 1 1

第一位客人8点的时候要了第一种炒饭1分,第二位客人8点04的时候要了第1种炒饭1份,那直接炒4份不就可以了吗...两位客人都是0点5分离开,坑啊,不能这样,正确的应该是这样联系实际,首先来的是第一位客人要了第一种炒饭1份,那么就得花5分钟就只炒1份,虽然这5分钟内有第二位客人来了,但是不能给他炒,等第一位客人走了以后,再给第二位客人来炒。

还有另外种情况,后面的可以加在前面炒

还是前面的数据,只不过客人的信息该为了

08:00 1 6

08:02 2 1

08:03 1 X

首先第一位客人,要了6份,因为一次最多炒4份,所以第一份炒完4份后,时间为8点05,这时候第二位和第三位都来了,正好第三位和第一位要的是一样的,那么下一次再为第一位客人炒饭(因为还差2份)时,就可以顺便为第三位客人也炒出来,如果X=2的话,那么最后一次为第一位客人炒饭,2份给它,2份给第三位个人就可以了,两位客人同时离开,如果X<2的话,假设为1,那么最后一次只要炒3份就可以了。如果X>2的话,那么炒出来2分给第三位客人留着,到了他的时候,再给他炒X-2份就够了.

写这道题,头晕晕的......

代码:

#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <stdlib.h>
#include <cmath>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cctype>
using namespace std;
#define ll long long
const int maxn=1002;//最大种类数
int n,t,K,M;//n为种类数,t为一次炒饭的时间,k为一次可以炒多少份,m是有m个客人
bool done[maxn];

struct Customer
{
    int h,m;
    int time;
    int kind;
    int num;
    int ans;
}cus[maxn];

void output(int t)
{
    int h=t/60;
    h%=24;
    int m=t%60;
    if(h<=9)
        printf("0%d:",h);
    else
        printf("%d:",h);
    if(m<=9)
        printf("0%d\n",m);
    else
        printf("%d\n",m);
}
int main()
{
    int T;scanf("%d",&T);
    while(T--)
    {
        scanf("%d%d%d%d",&n,&t,&K,&M);
        memset(done,0,sizeof(done));
        for(int i=1;i<=M;i++)
        {
            scanf("%d:%d %d %d",&cus[i].h,&cus[i].m,&cus[i].kind,&cus[i].num);
            cus[i].time=cus[i].h*60+cus[i].m;
        }
        int curtime=-1;//当前时间
        for(int i=1;i<=M;i++)
        {
            if(done[i])
                continue;
            if(cus[i].time>=curtime)
                curtime=cus[i].time;

            int c=(cus[i].num)/K;//为第i个顾客需要炒几次饭
            if(cus[i].num%K!=0)
                c++;
            //cout<<"tt"<<tt<<endl;
            cus[i].ans=curtime+c*t;//第i个顾客离开时间
            //int curt=curtime+cus[k].num/K*t;
            int curt=cus[i].ans-t;//为第i个顾客最后一次炒饭开始的时间,
            //因为这时候要看看后面的顾客有没有和当前顾客要的一样的,顺带着“炒出来一部分”

            curtime=cus[i].ans;
            int left=c*K-cus[i].num;//最后一次可以多炒一部分,比如每次炒4份,当前顾客要10份,那么得炒3次,第三次炒可以炒4份,那么就会多出来2份

            done[i]=1;
           // cout<<"kk"<<k<<"left"<<left<<endl;
            for(int j=i+1;j<=M;j++)
            {
                if(cus[j].time>curt)
                    break;
                if(cus[j].kind!=cus[i].kind)
                    continue;
                if(left>=cus[j].num)//当前顾客多出的饭可以直接给后面需要的
                {
                   // cout<<"inininininin"<<endl;
                    cus[j].ans=cus[i].ans;
                    done[j]=1;
                    left-=cus[j].num;
                }
                else
                {
                    cus[j].num-=left;
                    left=0;
                    break;
                }

            }
            //kindn[cus[k].kind]+=left;
            //cout<<cus[k].kind<<"  sssssssss   "<<left<<endl;
        }
        for(int i=1;i<=M;i++)
            output(cus[i].ans);
        if(T)
        printf("\n");
    }
    return 0;
}
时间: 2024-10-30 05:55:42

[ACM] HDU 4884 TIANKENG’s rice shop (模拟)的相关文章

hdu 4884 TIANKENG’s rice shop(模拟)

# include <cstdio> # include <algorithm> # include <cstring> # include <cstdlib> using namespace std; int max(int a,int b) { return a>b?a:b; } int main() { int T,n,t,k,m,i,hh,min,id,num,x; int last[1010];//最后一次開始炒饭的时间 int cot[10

HDU TIANKENG’s rice shop(模拟)

HDU 4884 TIANKENG's rice shop 题目链接 题意:模拟题.转一篇题意 思路:就模拟就可以.注意每次炒完之后就能够接单 代码: #include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int N = 1005; int T, n, t, k, m; struct Person { int t, p, num, ans; } p[N];

【HDOJ】4884 TIANKENG&#39;s rice shop

简单模拟,注意并不是完全按照FIFO的顺序.比如第i个人的id为k,那么就算第i+1人的id不为k,也会检查他后续的排队人是否有id为k的. 1 #include <cstdio> 2 #include <cstring> 3 #include <cstdlib> 4 5 #define MAXN 1005 6 7 typedef struct { 8 int tt; 9 int id; 10 int num; 11 int ans; 12 } need_st; 13

hdu4884 TIANKENG’s rice shop【模拟】

TIANKENG's rice shop Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 345    Accepted Submission(s): 71 Problem Description TIANKENG managers a pan fried rice shop. There are n kinds of fried ri

hdu4884TIANKENG’s rice shop(模拟)

题目:hdu4884TIANKENG's rice shop(模拟) 题目大意:一家餐厅买炒饭,给你客人来的时间和要买的炒饭的数量种类,并且也知道炒一次炒饭最多的分数和时间,问这些客人最早的离开时间.注意:每次炒饭的那段时间是不接单的. 解题思路:模拟.题意好坑,还有根本不会有23:59 , 00:00这样的输入数据,只是输出可能会跨一天.然后就是模拟了.好恶心的题目.详细的看注释把. 代码: #include <cstdio> #include <cstring> #includ

TIANKENG’s rice shop

Problem Description TIANKENG managers a pan fried rice shop. There are n kinds of fried rice numbered 1-n. TIANKENG will spend t time for once frying. Because the pan is so small, TIANKENG can fry k bowls of fried rice with same kind at most. Assumin

[ACM] HDU 4885 TIANKENG’s travel (特殊建图,最短路)

TIANKENG's travel Problem Description TIANKENG has get a driving license and one day he is so lucky to find a car. Every day he drives the car around the city. After a month TIANKENG finds that he has got high driving skills and he wants to drive hom

[ACM] HDU 4883 TIANKENG’s restaurant

TIANKENG's restaurant Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others) Total Submission(s): 931    Accepted Submission(s): 412 Problem Description TIANKENG manages a restaurant after graduating from ZCMU, and tens

HDU 4883 TIANKENG’s restaurant Bestcoder 2-1(模拟)

TIANKENG's restaurant Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others) Total Submission(s): 0    Accepted Submission(s): 0 Problem Description TIANKENG manages a restaurant after graduating from ZCMU, and tens of t