1376B高效超短代码。
VS2017上可以跑,放在POJ就Time Limit Extended。
糟心啊,不应该啊。
#include <iostream>
#include <string>
#include <queue>
using namespace std;
class cProcess
{
public:
cProcess();
cProcess(int t, int m, int p);
~cProcess();
int T, M, P;
};
cProcess::cProcess(){}
cProcess::cProcess(int t, int m, int p) :T(t), M(m), P(p) {}
cProcess::~cProcess(){}
int CountSpace(const string& s) {
int n = 0;
for (int i = 0; i < s.size(); i++) {
if (s[i] == 0)++n;
}
return n;
}
int main()
{
int N; cin >> N;
queue<cProcess> qCin;
int T, M, P;
while (cin >> T >> M >> P) {
if (T == 0 && M == 0 && P == 0)break;
qCin.push(cProcess(T, M, P));
}
int nTime = 0, nQueueMax = 0;
queue<cProcess> qQueue;
string sStatus(N, 0);
while (++nTime) {
for (int i = 0; i < N; i++) { if (sStatus[i] > 0)--sStatus[i]; }
if (qCin.size() > 0){
if (qCin.front().T == nTime) {
qQueue.push(qCin.front());
qCin.pop();
}
}
if (qQueue.size() > 0) {
if ((CountSpace(sStatus)) >= qQueue.front().M) {
while (qQueue.front().M--) {
for (int i = 0; i < N; i++) {if (sStatus[i] == 0) { sStatus[i] = qQueue.front().P; break; }}
}
qQueue.pop();
}
}
nQueueMax = (nQueueMax > qQueue.size()) ? nQueueMax : (int)qQueue.size();
if (qCin.size() == 0) {
bool flag = 1;
int i = N;
while (i--) {if (sStatus[i] != 0)flag = 0;}
if (flag == 1)break;
}
}
cout << --nTime << endl << nQueueMax << endl;
return 0;
}