HDU ACM 1103 Flo's Restaurant

分析:借助STL的min_element实现。每次更新最先被占用的桌子,具体见注释。

#include<iostream>
#include<algorithm>
using namespace std;

int main()
{
	int A,B,C;
	char s[10];
	int a[102],b[102],c[102];
	int curtime,count,ans;
	int *p;              //桌子最先空闲时间

	while(cin>>A>>B>>C,A+B+C)
	{
		memset(a,0,sizeof(a));
		memset(b,0,sizeof(b));
		memset(c,0,sizeof(c));
		ans=0;
		while(cin>>s && s[0]!='#')
		{
			curtime=(s[0]-'0')*10+(s[1]-'0');
			curtime=curtime*60+(s[3]-'0')*10+(s[4]-'0');
			cin>>count;

			if(count==1||count==2)
			{
				p=min_element(a,a+A);  //取得最小值(也即桌子的最早空余时间)
				if(*p<=curtime+30)            //顾客等30分钟后是否有座位
				{
					if(*p<=curtime) *p=curtime+30;  //最先被占用的桌子的顾客已经离开了,新顾客可以入座
					else *p+=30;        //新顾客还需等待
					ans+=count;
				}
			}
			if(count==3||count==4)
			{
				p=min_element(b,b+B);  //取得最小值(也即桌子的最早空余时间)
				if(*p<=curtime+30)            //顾客等30分钟后是否有座位
				{
					if(*p<=curtime) *p=curtime+30;  //最先被占用的桌子的顾客已经离开了,新顾客可以入座
					else *p+=30;        //新顾客还需等待
					ans+=count;
				}
			}
			if(count==5||count==6)
			{
				p=min_element(c,c+C);  //取得最小值(也即桌子的最早空余时间)
				if(*p<=curtime+30)            //顾客等30分钟后是否有座位
				{
					if(*p<=curtime) *p=curtime+30;  //最先被占用的桌子的顾客已经离开了,新顾客可以入座
					else *p+=30;        //新顾客还需等待
					ans+=count;
				}
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}

HDU ACM 1103 Flo's Restaurant

时间: 2024-08-08 10:34:49

HDU ACM 1103 Flo's Restaurant的相关文章

hdu 2368 Alfredo&#39;s Pizza Restaurant(简单数学题)

转载请注明出处:http://blog.csdn.net/u012860063 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2368 题目很简单,但是比较恶心,用sqrt WA到死也不过,不用秒过: 忍不住吐槽一下; Problem Description Traditionally after the Local Contest, judges and contestants go to their favourite restaurant,

POJ 2424 Flo&#39;s Restaurant 模拟

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 her desk job and built her own restaurant. In the s

hdu acm 1425 sort(哈希表思想)

sort Time Limit: 6000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 25803    Accepted Submission(s): 7764 Problem Description 给你n个整数,请按从大到小的顺序输出其中前m大的数. Input 每组测试数据有两行,第一行有两个数n,m(0<n,m<1000000),第二行包含n个各不相同,且

HDU ACM 1005 Number Sequence

Number Sequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 119732    Accepted Submission(s): 29072 Problem Description A number sequence is defined as follows:f(1) = 1, f(2) = 1, f(n) = (A

HDU1103 Flo&#39;s Restaurant 【模拟】

Flo's Restaurant Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 1112    Accepted Submission(s): 342 Problem Description Sick and tired of pushing paper in the dreary bleary-eyed world of finan

hdu acm 1166 敌兵布阵 (线段树)

敌兵布阵 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 37903    Accepted Submission(s): 15985 Problem Description C国的死对头A国这段时间正在进行军事演习,所以C国间谍头子Derek和他手下Tidy又开始忙乎了.A国在海岸线沿直线布置了N个工兵营地,Derek和Tidy的任务

HDU ACM 1025 Constructing Roads In JGShining&amp;#39;s Kingdom-&amp;gt;二分求解LIS+O(NlogN)

#include<iostream> using namespace std; //BFS+优先队列(打印路径) #define N 500005 int c[N]; int dp[N]; //dp[i]保存的是长度为i的最长不降子序列的最小尾元素 int BS(int n,int x) //二分查找下标,当x比全部元素小时下标为1,比全部元素大时下标为n+1. { int low,high,mid; low=1,high=n; while(low<=high) { mid=(low+h

杭电 HDU ACM 圆桌会议

圆桌会议 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 3356    Accepted Submission(s): 2351 Problem Description HDU ACM集训队的队员在暑假集训时经常要讨论自己在做题中遇到的问题.每当面临自己解决不了的问题时,他们就会围坐在一张圆形的桌子旁进行交流,经过大家的讨论后一般没有

杭电OJ(HDU)-ACM Steps-Chapter Two-《Biker&#39;s Trip Odometer》《Climbing Worm》《hide handkerchief》《Nasty Hac》

1.2.1 Biker's Trip Odometer #include<stdio.h> #include<math.h> const double PI=acos(-1.0); /* 计算题,根据公式做就行,PI*d*r/(12*5280);res1/t*3600; Sample Input 26 1000 5 27.25 873234 3000 26 0 1000 Sample Output Trip #1: 1.29 928.20 Trip #2: 1179.86 1415