1026. Table Tennis 解析
来源:互联网 发布:美国本周经济数据 编辑:程序博客网 时间:2024/06/07 09:08
你们尽管看我的程序,看得懂的算我输!!! (我自己都看不懂了......)
这个排队好麻烦。
我是按桌子来分类的。
1、VIP桌可用 :有人等待,有VIP先给VIP,没有给队列最前面的人。
没有人等待,给队列最前面的人。
2、普通桌可用:按顺序来。
3、VIP桌和普通桌都可以用:有人等待,有VIP先给VIP分配VIP桌,没有VIP给队列最前的人。优先号小的桌子
没人等待,给队列最前面的人。优先号小的桌子。
(但愿逻辑没错吧,我也乱了_(:з)∠)_)
#include <iostream>#include <string>#include <vector>#include <algorithm>#include <climits>#include <queue>#define MAX 10010#define MAX2 110#define EndTime 75600using namespace std;int N;int Table, VipTable;int ServeCount;//服务人数计数vector <int> Vipnum;struct Node{string arrive;int arriveTime;int time;int tag;int serveTime;int waitTime;bool isServe;int TabNum;};Node c[MAX];struct Tab {int Num;int time;int count;};vector <Tab> t; // 普通vector <Tab> tv;// VIPint c2int(char c){return int(c - '0');}int str2int(string s){int sum = 0;sum+= 3600 * (c2int(s[0]) * 10 + c2int(s[1]));sum += 60 * (c2int(s[3]) * 10 + c2int(s[4]));sum += c2int(s[6]) * 10 + c2int(s[7]);return sum;}bool cmp(Node n1, Node n2) {return str2int(n1.arrive) < str2int(n2.arrive);}bool cmp2(Tab t1, Tab t2) {return t1.Num < t2.Num;}bool cmp3(Node n1, Node n2) {return n1.serveTime < n2.serveTime;}int MinVipTab() {int ti = -1, min = INT_MAX;for (int i = 0; i < tv.size(); i++) {if (min > tv[i].time) {min = tv[i].time;ti = i;}}return ti;}int MinTab() {int ti = -1, min = INT_MAX;for (int i = 0; i < t.size(); i++) {if (min > t[i].time) {min = t[i].time;ti = i;}}return ti;}void Serve(Node * c) {int pv = MinVipTab();int p = MinTab();int HaveVip = false;int isFind = false;int ServeI = 0;bool st = true, isFindVip = false, isWait = false;vector <int> NoWait;//不需要等待vector <int> Wait;//需要等待if (tv[pv].time < t[p].time) { //VIP桌可用for (int i = 0; i < N; i++) {if (!c[i].isServe) {if (c[i].arriveTime < tv[pv].time) { //要等待Wait.push_back(i); isWait = true;}else {if (isWait) break; // 有需要等待的 必然没有不等待的else { //不需要等待 则直接用 没有人同时到NoWait.push_back(i); break;}}}}if (Wait.size() != 0) {//有需要等待的 int ti = Wait[0];for (int i = 0; i < Wait.size(); i++) {//查找是否有VIPif (c[Wait[i]].tag == 1) {//isFindVip = true;ti = Wait[i];break;}}c[ti].waitTime = tv[pv].time - c[ti].arriveTime;c[ti].serveTime = tv[pv].time;if (c[ti].serveTime < EndTime) {c[ti].isServe = true;tv[pv].count++;c[ti].TabNum = tv[pv].Num;}ServeCount--;tv[pv].time += c[ti].time;}else {//不需要等待int ti = NoWait[0];c[ti].waitTime = 0;c[ti].serveTime = c[ti].arriveTime;tv[pv].time = c[ti].arriveTime;if (c[ti].serveTime < EndTime) {c[ti].isServe = true;tv[pv].count++;c[ti].TabNum = tv[pv].Num;}ServeCount--;tv[pv].time += c[ti].time;}}else if(tv[pv].time > t[p].time){ //普通桌可用int ti = 0;for (int i = 0; i < N; i++) {if (!c[i].isServe) {ti = i;break;}}if (c[ti].arriveTime < t[p].time) { //需要等待c[ti].waitTime = t[p].time - c[ti].arriveTime;c[ti].serveTime = t[p].time;if (c[ti].serveTime < EndTime) {c[ti].isServe = true;t[p].count++;c[ti].TabNum = t[p].Num;}ServeCount--;t[p].time += c[ti].time;}else {c[ti].waitTime = 0;c[ti].serveTime = c[ti].arriveTime;t[p].time = c[ti].arriveTime;if (c[ti].serveTime < EndTime) {c[ti].isServe = true;t[p].count++;c[ti].TabNum = t[p].Num;}ServeCount--;t[p].time += c[ti].time;}}else { //普通桌和VIP桌相同for (int i = 0; i < N; i++) {if (!c[i].isServe) {if (c[i].arriveTime < tv[pv].time) { //要等待Wait.push_back(i);isWait = true;}else {if (isWait) break; // 有需要等待的 必然没有不等待的else { //不需要等待 则直接用 没有人同时到NoWait.push_back(i); break;}}}}if (Wait.size() != 0) {//有需要等待的 int ti = Wait[0];for (int i = 0; i < Wait.size(); i++) {//查找是否有VIPif (c[Wait[i]].tag == 1) {isFindVip = true;ti = Wait[i];break;}}if (isFindVip) {//有vipc[ti].waitTime = tv[pv].time - c[ti].arriveTime;c[ti].serveTime = tv[pv].time;if (c[ti].serveTime < EndTime) {c[ti].isServe = true;tv[pv].count++;c[ti].TabNum = tv[pv].Num;}ServeCount--;tv[pv].time += c[ti].time;}else {c[ti].waitTime = t[p].time - c[ti].arriveTime;c[ti].serveTime = t[p].time;if (c[ti].serveTime < EndTime) {c[ti].isServe = true;t[p].count++;c[ti].TabNum = t[p].Num;}ServeCount--;t[p].time += c[ti].time;}}else {//VIP桌和普通桌都能用 选号小的int ti = NoWait[0];if (c[ti].tag == 1) {//VIPc[ti].waitTime = 0;c[ti].serveTime = c[ti].arriveTime;tv[pv].time = c[ti].arriveTime;if (c[ti].serveTime < EndTime) {c[ti].isServe = true;tv[pv].count++;c[ti].TabNum = tv[pv].Num;}ServeCount--;tv[pv].time += c[ti].time;}else {if (tv[pv].Num > t[p].Num) {c[ti].waitTime = 0;c[ti].serveTime = c[ti].arriveTime;t[p].time = c[ti].arriveTime;if (c[ti].serveTime < EndTime) {c[ti].isServe = true;t[p].count++;c[ti].TabNum = t[p].Num;}ServeCount--;t[p].time += c[ti].time;}else {c[ti].waitTime = 0;c[ti].serveTime = c[ti].arriveTime;tv[pv].time = c[ti].arriveTime;if (c[ti].serveTime < EndTime) {c[ti].isServe = true;tv[pv].count++;c[ti].TabNum = tv[pv].Num;}ServeCount--;tv[pv].time += c[ti].time;}}}}}void printTime(int num) {int HH;int MM;int SS;HH = num / 3600;MM = num % 3600 / 60;SS = num % 3600 % 60;printf("%02d", HH);cout << ":";printf("%02d", MM);cout << ":";printf("%02d", SS);}void printMM(int MM){int isC = MM % 60;MM /= 60;if (isC >= 30) MM++;cout << MM;}int main() {cin >> N;ServeCount = N;for (int i = 0; i < N; i++) {cin >> c[i].arrive >> c[i].time >> c[i].tag;if (c[i].time > 120) {c[i].time = 120;}c[i].time *= 60;c[i].arriveTime = str2int(c[i].arrive);c[i].isServe = false;/*if (c[i].arriveTime <= 8 * 3600)while (1);*/}cin >> Table >> VipTable;Tab tempt;tempt.time = 8*3600;tempt.count = 0;for (int i = 0; i < VipTable; i++) {cin >> tempt.Num;tempt.Num--;tv.push_back(tempt);}sort(&tv[0], &tv[0] + VipTable, cmp2);for (int i = 0,j =0; i < Table; i++) {if (i != tv[j].Num) {tempt.Num = i;t.push_back(tempt);}}#ifdef _DEBUGfor (int i = 0; i < t.size(); i++) {cout << t[i].Num << " " << t[i].time << " " << t[i].count << endl;}for (int i = 0; i < tv.size(); i++) {cout << tv[i].Num << " " << tv[i].time << " " << tv[i].count << endl;}#endifsort(&c[0], &c[0] + N, cmp);#ifdef _DEBUGfor (int i = 0; i < N; i++) {cout << c[i].arrive << " " << c[i].time /60 << " "<< str2int(c[i].arrive) << " ";if (c[i].tag == 1)cout << " VIP ";elsecout << " NoV ";cout << endl;}#endif//for (int i = 0; i < N; i++) {//Serve(c[i]);//}while (ServeCount) {Serve(c);}sort(&c[0], &c[0] + N, cmp3);for (int i = 0; i < N; i++) {if (c[i].isServe) {cout << c[i].arrive << " ";printTime(c[i].serveTime);cout << " ";printMM(c[i].waitTime);#ifdef _DEBUGcout << " " << c[i].TabNum + 1;if (c[i].tag == 1)cout << " VIP ";elsecout << " NoV ";#endifcout << endl;}}vector <Tab> golbeT;for (int i = 0; i < tv.size(); i++) {golbeT.push_back(tv[i]);}for (int i = 0; i < t.size(); i++) {golbeT.push_back(t[i]);}sort(&golbeT[0], &golbeT[0] + Table, cmp2);for (int i = 0; i < Table -1 ; i++) {cout << golbeT[i].count << " ";}cout << golbeT[Table - 1].count << endl;system("pause");return 0;}
0 0
- 1026. Table Tennis 解析
- 1026. Table Tennis (30)
- 1026. Table Tennis (30)
- 1026. Table Tennis (30)
- PAT 1026. Table Tennis
- 1026. Table Tennis
- 1026. Table Tennis (30)
- 1026. Table Tennis (30)
- 1026.Table Tennis
- 1026. Table Tennis (30)
- 1026. Table Tennis (30)
- 1026. Table Tennis (30)
- 1026. Table Tennis (30)
- 1026. Table Tennis (30)
- 1026. Table Tennis (30)
- 1026. Table Tennis (30)
- 1026. Table Tennis (30)
- 1026. Table Tennis (30)
- Android Intent Flag的介绍
- Reflux原理与源码详解
- 如何安装服务器操作系统 HP服务器系统安装
- 静态页面技术
- 20170207 细边框表格
- 1026. Table Tennis 解析
- android拨打电话崩溃6.0以上实时动态权限申请
- StringUtils方法全集
- pdf编辑软件如何修改pdf文件
- redis 常用配置
- HTTPS证书本地生成和在nginx上的部署细节
- Java命名规则
- 失物招领-2数据库
- Java synchronized 可重入锁 基本概念