Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
Register

## 优先队列 32MS水果

Posted by magiccaptain at 2013-04-24 23:52:35 on Problem 2051
#include <iostream>
#include <queue>
#include <stdio.h>
#include <string.h>
using namespace std;

class Query
{
public:
int _query_num;
int _nextReturnTime;
int _period;

bool operator < ( const Query &o ) const
{
if ( _nextReturnTime > o._nextReturnTime )
return true;
else if ( _nextReturnTime == o._nextReturnTime )
return _query_num > o._query_num;
else
return false;
}
};
int main ( int argc, char **argv )
{
Query querys[3001];
priority_queue<Query> que;

string str;
while ( cin >> str )
{
if ( str == "Register" )
{
int Q_id, peroid;
cin >> Q_id >> peroid;

querys[Q_id]._period = peroid;
querys[Q_id]._nextReturnTime = peroid;
querys[Q_id]._query_num = Q_id;

que.push ( querys[Q_id] );
}

if ( str == "#" )
{
int k;
cin >> k;

for ( int i = 0; i < k; i++ )
{
int Q_id = que.top()._query_num;
cout << Q_id << endl;
que.pop();

querys[Q_id]._nextReturnTime+=querys[Q_id]._period;
que.push(querys[Q_id]);
}
}
}

}
// kate: indent-mode cstyle; indent-width 4; replace-tabs on;

Followed by: