| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
优先队列 32MS水果
#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: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator