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 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

分析:普通模拟,卡了一天。

代码示例:

#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
#define Max(a,b) a>b?a:b
using namespace std;
typedef struct
{
    int time,id,num;
}node;
typedef struct
{
    int time,s,t,id;
}nodf;
node E[2000+10];
int Time[2000+10];
int main()
{
    int T,n,t,k,m;
    int a,b,c,d;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%d%d%d%d",&n,&t,&k,&m);
        for(int i=0;i<m;i++)
        {
            scanf("%d:%d%d%d",&a,&b,&c,&d);
            E[i].time=a*60+b,E[i].id=c,E[i].num=d;
            Time[i]=-1;
        }
        nodf sum;
        sum.time=-1;
        for(int i=0;i<m;i++)
        {
            if(Time[i]!=-1)
            continue;
            sum.time=Max(sum.time,E[i].time);
            sum.s=sum.t=0,sum.id=E[i].id;
            while(sum.s<E[i].num)
            {
                sum.s+=k;
                sum.t+=t;
            }
            Time[i]=sum.time+sum.t;
            sum.time+=(sum.t-t),sum.s-=E[i].num;
            int j=i+1;
            while(E[j].time<=sum.time&&sum.s>0&&j<m)
            {
                if(E[j].num>sum.s&&E[j].id==sum.id)
                {
                    E[j].num-=sum.s;
                    sum.s=0;
                }
                if(E[j].num<=sum.s&&E[j].id==sum.id)
                {
                    sum.s-=E[j].num;
                    Time[j]=sum.time+t;
                }
                j++;
            }
            sum.time+=t;
        }
        for(int i=0;i<m;i++)
        {   
            a=Time[i]/60,b=Time[i]%60;
            a%=24;
            printf("%02d:%02d\n",a,b);
        }
        if(T>0)
        printf("\n");
}
return 0;
}        
             

时间: 2024-10-15 23:16:31

hdu4884 TIANKENG’s rice shop【模拟】的相关文章

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];

[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

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

【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

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

URAL1795. Husband in a Shop(模拟,首次探访俄罗斯的oj)

1795. Husband in a Shop Time limit: 1.0 second Memory limit: 64 MB Mark comes home after a day of hard work. His wife, instead of feeding him, sends him to buy some bread. When Mark comes to a local shop, there is a long line of equally unhappy husba

HDOJ 4884 &amp; BestCoder#2 1002

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

spring实现读写分离

(转自:http://www.cnblogs.com/surge/p/3582248.html) 现在大型的电子商务系统,在数据库层面大都采用读写分离技术,就是一个Master数据库,多个Slave数据库.Master库负责数据更新和实时数据查询,Slave库当然负责非实时数据查询.因为在实际的应用中,数据库都是读多写少(读取数据的频率高,更新数据的频率相对较少),而读取数据通常耗时比较长,占用数据库服务器的CPU较多,从而影响用户体验.我们通常的做法就是把查询从主库中抽取出来,采用多个从库,使