BZOJ 1216 HNOI 2003 操作系统 堆

题目大意

给出一个CPU处理事件的规则,给出一些事件,问处理这些事件的顺序和结束时间。

思路

我们只需要维护一个堆来模拟他说的规则,之后按顺序输出就行了。

CODE;struct Complex{int no, arrive, lasting, priority;bool operator <(const Complex &a)const {if(priority == a.priority)return arrive > a.arrive;return priority < a.priority;}void Read() {scanf(“%d%d%d”, &arrive, &lasting, &priority);}}src[MAX];int cnt;priority_queue<Complex> q;int rest[MAX];int main(){int x;while(scanf(“%d”, &x) != EOF) {src[++cnt].no = x;src[cnt].Read();rest[src[cnt].no] = src[cnt].lasting;}q.push(src[1]);int now_time = src[1].arrive;for(int i = 2; i <= cnt; ++i) {while(!q.empty() && now_time + rest[q.top().no] <= src[i].arrive) {Complex temp = q.top();q.pop();now_time += rest[temp.no];printf(“%d %d\n”, temp.no, now_time);}if(!q.empty())rest[q.top().no] -= src[i].arrive – now_time;now_time = src[i].arrive;q.push(src[i]);}while(!q.empty()) {now_time += rest[q.top().no];printf(“%d %d\n”, q.top().no, now_time);q.pop();}return 0;}

,我知道有一种爱情,叫做与你白头,有一种幸福,叫做和你相伴。

BZOJ 1216 HNOI 2003 操作系统 堆

相关文章:

你感兴趣的文章:

标签云: