您的位置:首页 > 其它

银行排队问题之单队列多窗口加VIP服务(30 分)

2017-10-28 19:49 603 查看
这个题,就是需要注意一个地方,需要改变这个系列题目方式,需要暴力时间求解,就是对于每一个时间,都有一个标记值,如果这个时间已经被标记过了,然后++

直接找到一个区间可以使这个人能够办完业务,比较恶心,直接暴力写就行,剩下的就是复制粘贴。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <math.h>
#include <stack>
#include <utility>
#include <string>
#include <sstream>
#include <cstdlib>
#include <set>
#define LL long long
using namespace std;
const int INF = 0x3f3f3f3f;
const int maxn = 1000 + 10;
int dir[4][2] = {{1,0},{0,1},{-1,0},{0,-1}};
struct Per
{
int p,t1,vip,wait,leave;
} Index[maxn];
int Win[15][maxn * 60];
int vis[maxn];
int num[20];
int n,m,cnt;
int v;
void slove()
{
int waitime = 0,maxwait = 0,finishtime = 0;
for(int i = 0; i < n; i++)
{
waitime += Index[i].wait;
maxwait = max(maxwait,Index[i].wait);
finishtime = max(finishtime,Index[i].leave);
}
printf("%.1lf %d %d\n",waitime*1.0 / n,maxwait,finishtime);
for(int i = 0; i < m; i++)
{
if(!i)
printf("%d",num[i]);
else
printf(" %d",num[i]);
}
}
int main()
{
scanf("%d",&n);
memset(Win,0,sizeof(Win));
memset(num,0,sizeof(num));
memset(vis,0,sizeof(vis));
for(int i = 0; i < n; i++)
{
scanf("%d %d %d",&Index[i].p,&Index[i].t1,&Index[i].vip);
if(Index[i].t1 > 60)
Index[i].t1 = 60;
Index[i].wait = Index[i].leave = 0;
}
scanf("%d %d",&m,&v);
cnt = 0;
for(int t = 0; cnt < n; t++)
{
if(Win[v][t] == 0)
{
for(int i = 0; i < n; i++)
{
if(vis[i] == 1 || Index[i].vip == 0) continue;
if(Index[i].p > t) break;
vis[i] = 1;
Index[i].wait = t - Index[i].p;
Index[i].leave = t + Index[i].t1;
num[v]++;
cnt++; //cout<<"^^^^^"<<cnt<<endl;
for(int j = t; j < t + Index[i].t1; j++)
Win[v][j] = 1;
break;
}
}
for(int j = 0; j < m; j++)
{
if(Win[j][t] == 0)
{
for(int i = 0; i < n; i++)
{
if(vis[i] == 1) continue;
if(Index[i].p > t) break;
vis[i] = 1;
Index[i].wait = t - Index[i].p;
Index[i].leave = t + Index[i].t1;
num[j]++;
cnt++;
//cout<<"^^^^^"<<cnt<<endl;
for(int k = t; k < t + Index[i].t1; k++)
Win[j][k] = 1;
break;
}
}
}
}
slove();
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: