//这题模拟题搞死人了:首先桌子是分类的,如果你来的人数是1或者2,只可以坐 two-seat tables类型,如果你来的人数是2或者3人,只可以坐
// four-seat tables 类型,如果来的人数是5或者6人,只可以坐 six-seat tables类型,就算其他的桌子类型有空出来了,你也不可以坐,你只可以
//等你所需要的那种类型;第二个值得注意的地方就是:they have to wait until some suitable table is free and
//there isn't an earlier arrival group waiting for the same kind of tables 。即是说如果前面一个团队等的正是你所需要的桌子类型,客人就
//不再等待,直接离开!就是因为后面要点的没有注意到,一直在WA!
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
struct Info
{
int time;
int num;
}customer;
vector<Info> v[3];
struct info
{
int cometime;
int lefttime;
}cus;
vector<info> vv[3];
bool cmp(info a, info b)
{
return a.lefttime < b.lefttime;
}
int main()
{
int i, j, a, b, c, temp, n, ans;
string str;
while (cin >> a >> b >> c)
{
if (a == 0 && b == 0 && c == 0) break;
for (i = 0; i < 3; i++)
{
v[i].clear();
vv[i].clear();
}
while (cin >> str)
{
if (str == "#") break;
cin >> n;
temp = (((str[0]-48)*10 + (str[1]-48)))*60 + (str[3]-48)*10 + str[4]-48;
customer.time = temp;
customer.num = n;
//按桌子的类型来进行归类
if (n >= 1 && n <= 2)
{
v[0].push_back(customer);
}
else if (n >= 3 && n <= 4)
{
v[1].push_back(customer);
}
else if (n >= 5 && n <= 6)
{
v[2].push_back(customer);
}
}
//对第一种类型的桌子进行求解人数
ans = 0;
if (v[0].size() > 0)
{
for (i = 0; i < a; i++)
{
cus.cometime = 0;
cus.lefttime = 0;
vv[0].push_back(cus);
}
for (i = 0; i < v[0].size(); i++)
{
if(v[0][i].time >= vv[0][0].lefttime)//看是否需要等待
{
vv[0][0].lefttime = v[0][i].time+30;
ans += v[0][i].num;
}
else if(v[0][i].time >= vv[0][0].cometime)//看是否前面的团队在等待
{
vv[0][0].cometime = vv[0][0].lefttime;
vv[0][0].lefttime += 30;
ans += v[0][i].num;
}
sort(vv[0].begin(), vv[0].end(), cmp);//每一次都进行一个排序,就可以得出最早离开的桌子数了,就不用考虑还有几张桌子可用!
}
}
//对第二种类型的桌子进行求解人数
if (v[1].size() > 0)
{
for (i = 0; i < b; i++)
{
cus.cometime = 0;
cus.lefttime = 0;
vv[1].push_back(cus);
}
for (i = 0; i < v[1].size(); i++)
{
if(v[1][i].time >= vv[1][0].lefttime)
{
vv[1][0].lefttime = v[1][i].time+30;
ans += v[1][i].num;
}
else if(v[1][i].time >= vv[1][0].cometime)
{
vv[1][0].cometime = vv[1][0].lefttime;
vv[1][0].lefttime += 30;
ans += v[1][i].num;
}
sort(vv[1].begin(), vv[1].end(), cmp);
}
}
//对第三种类型的桌子进行求解人数
if (v[2].size() > 0)
{
for (i = 0; i < c; i++)
{
cus.cometime = 0;
cus.lefttime = 0;
vv[2].push_back(cus);
}
for (i = 0; i < v[2].size(); i++)
{
if(v[2][i].time >= vv[2][0].lefttime)
{
vv[2][0].lefttime = v[2][i].time+30;
ans += v[2][i].num;
}
else if(v[2][i].time >= vv[2][0].cometime)
{
vv[2][0].cometime = vv[2][0].lefttime;
vv[2][0].lefttime += 30;
ans += v[2][i].num;
}
sort(vv[2].begin(), vv[2].end(), cmp);
}
}
cout << ans << endl;
}
system("pause");
}
/*
1 1 1
10:40 1
10:50 2
11:00 4
#
1 1 1
10:40 1
10:50 2
11:00 2
#
1 1 1
10:30 1
10:40 3
10:50 2
11:00 1
11:19 5
11:20 6
#
1 1 1
07:00 2
08:00 2
10:00 2
#
1 1 1
07:59 2
10:00 6
23:10 2
#
11 12 13
08:00 2
08:01 2
08:03 2
09:00 4
09:01 4
09:03 3
12:00 5
12:01 6
20:00 3
#
0 0 0
*/
poj 2424 Flo's Restaurant
最新推荐文章于 2022-02-25 19:38:17 发布