码迷,mamicode.com
首页 > 其他好文 > 详细

HDU ACM 1103 Flo's Restaurant

时间:2015-05-02 01:10:24      阅读:161      评论:0      收藏:0      [点我收藏+]

标签:c   c++   acm   算法   开发者   

分析:借助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

标签:c   c++   acm   算法   开发者   

原文地址:http://blog.csdn.net/a809146548/article/details/45424805

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!