优先队列的应用
好坑,好坑,好坑,重要的事情说三遍!
#include<iostream> #include<cstdio> #include<cstring> #include<queue> using namespace std; #define maxn 50005 struct Node { int f,s,id; friend bool operator < (Node a,Node b) { if(a.f != b.f) return a.f < b.f; else return a.id > b.id; } } node[maxn]; priority_queue<Node>que[110]; int main() { int t,n,Case = 0; scanf("%d",&t); while(t--) { scanf("%d",&n); for(int i = 0; i < n; i++) { scanf("%d%d",&node[i].f,&node[i].s); node[i].id = i+1; que[node[i].s].push(node[i]); } printf("Case #%d: ",++Case); int now = 0; while(n--) { int maxt = -9999,minid = 999,pos = 0; for(int i = 0; i <= 100; i++) { if(!que[i].empty()) { Node te = que[i].top(); int tmp = te.f + te.s*now; if(tmp > maxt) { maxt = tmp; minid = te.id; pos = i; } if(tmp == maxt) { if(te.id < minid) { minid = te.id; pos = i; } } } } if(!que[pos].empty())que[pos].pop(); if(n == 0) printf("%d",minid); else printf("%d ",minid); now++; } puts(""); } }