stl2C
未完成的错误代码
#include<iostream>
#include<algorithm>
#include<iomanip>
#include<cstring>
#include<string>
#include<queue>
#include<vector>
using namespace std;
struct node
{
int id, time, num, ans;
node(int x, int y, int z)
{
id = x;
time = y;
num = z;
}
};
int main()
{
vector<node> ans;
queue<node> que[12];
freopen("C:\\Users\\bearb\\Desktop\\in.txt", "r", stdin);
int T;
cin >> T;
while(T--)
{
//n: n kinds of fried rice 1-n
//t: t time for once frying
//k: fry k bowls of fried rice with same kind at most
//m: m customers
//serve the customer who comes earlier and he will fry the rice as much as possible
//the earlier they arrive, the more front they stand
//m lines ,a time(hh:mm, 0<=hh<=23, 0<=mm<=59),id(1<=id<=n), num(1<=num<=10),the brand number of the fried rice and the number of the fried rice the customer needs
//There is a blank line between two test cases.
int n, t, k, m, cus[60];
cin >> n >> t >> k >> m;
int time ,id, num;
for(int i = 0; i < m; i++)
{
cin >> time>> id >> num;//change time
que[id].push(node(i, time, num));
cus[i] = id;//预备访问列表
}
int cnt = 0;//the id of serving people
int now = time;//time now
int state = 0;//0->not work 1->work
while(cnt < m)
{
if(cus[cnt] != -1)//这个人没有被预先服务过了(已经pop)
{
now += (que[cus[cnt]].front().num / k) * t;//先满足它
int num = que[cus[cnt]].front().num % k;//剩下的部分
//讨论是否需要凑单
if(num==0)
{
que[cus[cnt]].front().ans = now;
ans.push_back(que[cus[cnt]].front());
que[cus[cnt]].pop();
continue;
}
else
{
//这个人已经确定凑好了
que[cus[cnt]].front().ans = now + k;
ans.push_back(que[cus[cnt]].front());
que[cus[cnt]].pop();
while(num < k)//还没凑好单
{
if(que[cus[cnt]].empty()==0 && que[cus[cnt]].front().time <= now)//有人可以凑单
{
if(que[cus[cnt]].front().num+num <= k)//这个人可以被凑掉
{
num += que[cus[cnt]].front().num;//算上这个人的需求
//这个人已经被凑掉了
que[cus[cnt]].front().ans = now+k;
ans.push_back(que[cus[cnt]].front());
cus[que[cus[cnt]].front().id] = -1;
que[cus[cnt]].pop();
}
else
{
que[cus[cnt]].front().num - (k-num);//先给他几份
num = k;//达到饱和了自动退出
}
}
else
break;
}
now += t;//做好了
}
}
cnt++;
}
}
return 0;
}