模拟

思路挺好想的,就是模拟

当然要按照开始时间和优先度排序,然后在进行模拟

模拟方法就是每次读入一个数,如果当前结束时间小于下一个的开始时间,那就加入堆

代码

#include <bits/stdc++.h> #define maxn 21000 using namespace std ; struct dy{ int num , start , cost , pow ; int operator < (const dy &a) const { if(pow == a.pow) return start > a.start ; else return pow < a.pow ; } }a ; int ti , t ; priority_queue<dy>q ; int main () { // while(cin >> a[++t].num >> a[t].start >> a[t].cost >> a[t].pow) ; // sort(a+1,a+1+t,cmp) ; // int now = 1 ; while(cin >> a.num >> a.start >> a.cost >> a.pow) { while(!q.empty() && ti + q.top().cost <= a.start) { dy b = q.top() ; q.pop() ; cout << b.num << " " << ti+b.cost << endl ; ti += b.cost ; } if(!q.empty() ) { dy d = q.top() ; q.pop() ; d.cost = d.cost - a.start + ti ; q.push(d) ; } q.push(a) ; ti = a.start ; } while(!q.empty()) { dy d = q.top() ; q.pop() ; ti += d.cost ; cout << d.num << " " << ti << endl ; } return 0 ; }

溜了溜了