2013年8月24日

UVa 1203 - Argus

#include <cstdio>
#include <queue>
using namespace std;

struct Event {
  bool operator<(const Event & other) const {
    return (triggerTime != other.triggerTime) ? (triggerTime > other.triggerTime) : (id > other.id);
  }
  int id, triggerTime, period;
};

int main() {
  char s[99];
  int id, p;
  priority_queue<Event> pq;
  while (scanf("%s", s) && *s != '#') {
    scanf("%d%d", &id, &p);
    pq.push((Event){id, p, p});
  }
  int times;
  scanf("%d", &times);
  while (times--) {
    Event event = pq.top();
    pq.pop();
    printf("%d\n", event.id);
    event.triggerTime += event.period;
    pq.push(event);
  }
  return 0;
}

沒有留言:

張貼留言