1026. Table Tennis (30)
2015-06-04 13:19
337 查看
有几点需要注意:
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
;
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
;//记录客户是否已经被服务
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;
}
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
;
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
;//记录客户是否已经被服务
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;
}
相关文章推荐
- apple - 屏幕适配 - 发展历程
- 获取任意两个数之间的一个随机数的方法;
- oracle link
- 在Windows系统中配置Mysql群集(Mysql Cluster)
- ALSA record wave has noise
- Java 垃圾回收机制概念梳理
- 欢迎加入iOS开发初学者交流群:180080550
- 读取网络图片下载到SD卡并显示在ImageView中
- 【深入了解cocos2d-x 3.x】定时器(scheduler)的使用和原理探究(2)
- oracle 备份脚本
- React Native
- 交互设计到底是什么
- 文章标题
- log4cplus指南
- 课程的改进意见
- weka简介
- 实验三 Java猜数字游戏开发
- Home界面的ListView
- SAT数学题库精选试题
- linux 断电后出现问题