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

不明白不用STL的是什么心态(附代码)

Posted by jordandandan at 2013-08-21 09:42:54 on Problem 2051
#include <iostream>
#include <queue>
#include <vector>
#include <memory.h>
using namespace std;
typedef struct
{
    int time;
    int period;
    int id;
} Reg;
struct cmp
{
    bool operator()( Reg a, Reg b)
    {
        if(a.time == b.time)
          return a.id>b.id;
        else
          return a.time>b.time;
    }
};
int main()
{
    char temp[10];
    int id,period;
    priority_queue<Reg,vector<Reg>,cmp> q;
    while(cin>>temp)
      if(temp[0]=='#')
      break;
      else
      {
          Reg r;
          cin>>id>>period;
          r.id = id;
          r.period = period;
          r.time = period;
          q.push(r);
      }
      int k;
      cin>>k;
      while(k--)
      {
          Reg r = q.top();
          cout<<r.id<<endl;
          r.time += r.period;
          q.pop();
          q.push(r);
      }
    return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator