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

int main() {
    scanf("%d", &T);
    while (T--) {
	scanf("%d%d%d%d", &n, &t, &k, &m);
	for (int i = 0; i < m; i++) {
	    int a, b;
	    scanf("%d:%d%d%d", &a, &b, &p[i].p, &p[i].num);
	    p[i].t = a * 60 + b;
	}
	int ti = p[0].t, i = 0;
	while (1) {
	    if (p[i].num == 0) {
		i++;
		if (i == m) break;
		continue;
	    }
	    if (i == m) break;
	    ti = max(ti, p[i].t);
	    int st = ti;
	    int pz = p[i].p;
	    int have = k;
	    while (have < p[i].num) {
		p[i].num -= have;
		ti += t;
	    }
	    have -= p[i].num;
	    p[i].num = 0;
	    st = ti;
	    ti += t;
	    p[i].ans = ti;
	    for (int j = i + 1; p[j].t <= st && j < m && have; j++) {
		if (p[j].p != pz) continue;
		if (p[j].num == 0) continue;
		if (p[j].num > have) {
		    p[j].num -= have;
		    have = 0;
		}
		else {
		    have -= p[j].num;
		    p[j].ans = ti;
		    p[j].num = 0;
		}
	    }
	}
	for (int i = 0; i < m; i++)
	    printf("%02d:%02d\n", p[i].ans / 60 % 24, p[i].ans % 60);
	if (T) printf("\n");
    }
    return 0;
}
时间: 2024-10-24 22:30:46

HDU TIANKENG’s rice shop(模拟)的相关文章

[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

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

【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

Hdu 3887树状数组+模拟栈

题目链接 Counting Offspring Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1757    Accepted Submission(s): 582 Problem Description You are given a tree, it’s root is p, and the node is numbered fr

hdu 4891 The Great Pan(模拟)

题目链接:hdu 4891 The Great Pan 题目大意:给出一个文本,问说有多少种理解方式. 1. $$中间的,(s1+1) * (s2+1) * ...*(sn+1), si表示连续的空格数. 2.{}中间,即 | 的个数+1. 解题思路:模拟. #include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int maxn = 1<<22

HDU 4930 Fighting the Landlords 模拟

_(:зゝ∠)_ 4带2居然不是炸弹,, #include <algorithm> #include <cctype> #include <cassert> #include <cstdio> #include <cstring> #include <climits> #include <vector> #include<iostream> using namespace std; #define N 18 #