1026. Table Tennis (30)

 有几点需要注意:

1.客户服务时间不超过2小时

2.等待时间需要四舍五入到分钟

3.普通会员到达时,选择编号最小的空闲桌子(VIP桌子在内)

4.vip会员到达时,优先选择编号最小的vip桌子

5.客户>=21点到达不被服务,客户开始被服务时间>=21点也不能再服务


#define  _CRT_SECURE_NO_WARNINGS 
#include<string>
#include<string.h>
#include<vector>
#include<map>
#include<iostream> 
#include<algorithm>
#include<stdio.h> 
using namespace std;
struct Customer
{
int arrTime, startTime, cost;
int privilege;
Customer()
{
arrTime = 0;
startTime = 0;
cost = 0;
privilege = 0;
}
};
struct Window
{
int count;
int privilege;
int deadTime;
Window()
{
count = 0;
privilege = 0;
deadTime = 28800;
}
};
bool cmp(Customer a, Customer b)
{
return a.arrTime < b.arrTime;
}
bool cmpS(Customer a, Customer b)
{
return a.startTime < b.startTime;
}
int FindMin(Window *win,int M)
{
int mark = 0;
int min = win[0].deadTime;
for (int i = 1; i < M; i++)
{
if (win[i].deadTime < min)
{
min = win[i].deadTime;
mark = i;
}
}
return mark;
}
int FindDex(int arrTime,int M,Window *win)
{
for (int i = 0; i < M; i++)
if (win[i].deadTime <= arrTime)
return i;
return 0;
}
int FindVipTable(int M,int time,Window *win)
{
for (int i = 0; i < M; i++)
{
if (win[i].privilege == 1 && win[i].deadTime <= time)
{
return i;
}
}
return -1;
}
bool HavePrivilige(int i, int N, int deadTime, Customer *cust, bool *deal, int&mark)

bool bFind = false;
for (; i < N&&cust[i].arrTime<= deadTime; i++)
{
if (!deal[i])
if (cust[i].privilege == 1)
{
bFind = true;
mark = i;
break;
}
}
return bFind;
}
int main()
{
int N;
cin >> N;
Customer *cust = new Customer[N];
for (int i = 0; i < N; i++)
{
int h, m, s;
scanf("%d:%d:%d",&h,&m,&s);
cust[i].arrTime = h * 3600 + m * 60 + s;
cin >> cust[i].cost >> cust[i].privilege;
cust[i].cost = cust[i].cost * 60;
if (cust[i].cost > 7200)
cust[i].cost = 7200;
}
sort(cust, cust + N, cmp);
int M;
cin >> M;
Window *win = new Window[M];
int count;
cin >> count;
for (int i = 0; i < count; i++)
{
int iNum;
cin >> iNum;
win[iNum - 1].privilege = 1;
}
bool *deal = new bool[N];//记录客户是否已经被服务
memset(deal, 0, sizeof(bool)*N);
for (int i = 0; i < N; i++)
{
if (deal[i])
continue; 
int iMinDex = FindMin(win, M);
if (win[iMinDex].deadTime >= 75600 || cust[i].arrTime>=75600)
break;
if (cust[i].arrTime >= win[iMinDex].deadTime)
{
if (cust[i].privilege == 1)//查找时间小于到达时间且编号最小的vip桌子
{
int iMinvip = FindVipTable(M, cust[i].arrTime, win);
if (iMinvip != -1)
{
cust[i].startTime = cust[i].arrTime;
win[iMinvip].count++;
win[iMinvip].deadTime = cust[i].startTime + cust[i].cost;
deal[i] = true;
continue;

}
//找到编号最小且deadTime<=arrTime的窗口
int dex = FindDex(cust[i].arrTime, M, win);
cust[i].startTime = cust[i].arrTime;
win[dex].count++;
win[dex].deadTime = cust[i].startTime + cust[i].cost;
deal[i] = true;
}
else
{
//窗口处理完成时,已经有客户在等待  
//如果窗口为特权窗口,当前等待的客户中有特权客户
int iFp;
if (win[iMinDex].privilege == 1 && HavePrivilige(i, N, win[iMinDex].deadTime, cust, deal, iFp))
{
cust[iFp].startTime = win[iMinDex].deadTime;
win[iMinDex].count++;
win[iMinDex].deadTime = cust[iFp].startTime + cust[iFp].cost;
deal[iFp] = true;
i--;
}
else//否则
{
cust[i].startTime = win[iMinDex].deadTime;
win[iMinDex].count++;
win[iMinDex].deadTime = cust[i].startTime + cust[i].cost;
deal[i] = true;
}
}
}
sort(cust, cust + N, cmpS);
for (int i = 0; i < N; i++)
{
if (cust[i].startTime == 0 || cust[i].startTime >= 75600)
continue;
printf("%02d:%02d:%02d %02d:%02d:%02d %d\n", cust[i].arrTime / 3600, (cust[i].arrTime % 3600) / 60, cust[i].arrTime%60,
cust[i].startTime / 3600, (cust[i].startTime % 3600) / 60, cust[i].startTime % 60,(cust[i].startTime-cust[i].arrTime+30)/60);
}
cout << win[0].count;
for (int i = 1; i < M; i++)
cout <<" "<< win[i].count;
return 0;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
The following is the data that you can add to your input file (as an example). Notice that the first line is going to be a line representing your own hobbies. In my case, it is the Vitaly,table tennis,chess,hacking line. Your goal is to create a class called Student. Every Student will contain a name (String) and an ArrayList<String> storing hobbies. Then, you will add all those students from the file into an ArrayList<Student>, with each Student having a separate name and ArrayList of hobbies. Here is an example file containing students (the first line will always represent yourself). NOTE: eventually, we will have a different file containing all our real names and hobbies so that we could find out with how many people each of us share the same hobby. Vitaly,table tennis,chess,hacking Sean,cooking,guitar,rainbow six Nolan,gym,piano,reading,video games Jack,cooking,swimming,music Ray,piano,video games,volleyball Emily,crochet,drawing,gardening,tuba,violin Hudson,anime,video games,trumpet Matt,piano,Reading,video games,traveling Alex,swimming,video games,saxophone Roman,piano,dancing,art Teddy,chess,lifting,swimming Sarah,baking,reading,singing,theatre Maya,violin,knitting,reading,billiards Amy,art,gaming,guitar,table tennis Daniel,video games,tennis,soccer,biking,trumpet Derek,cooking,flute,gaming,swimming,table tennis Daisey,video games,guitar,cleaning,drawing,animated shows,reading,shopping Lily,flute,ocarina,video games,baking Stella,roller skating,sudoku,watching baseball,harp Sophie,viola,ukulele,piano,video games
06-10
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值