1216: [HNOI2003]操作系统

来源:互联网 发布:关于猫的淘宝昵称 编辑:程序博客网 时间:2024/06/06 01:01

又到了切水题的时间了。。。。。

由于众所周知的坑爹规定,03年木有STL,于是就会有如此水的heap题。

按照题目模拟一遍即可,因为比较懒,所以在最后加了个小玩意然后就代码就很短,900b整。

#include<iostream>#include<cstdio>#include<cstring>#include<queue>#define inf 1LL<<62using namespace std;typedef long long ll;struct Heapnode{int id;ll rea,pro;int pri;bool operator<(const Heapnode &rhs)const{if(pri==rhs.pri)return rea>rhs.rea;return pri<rhs.pri;}};priority_queue<Heapnode>pro;ll now;void work(Heapnode a){ll rest=a.rea-now;while(pro.size()&&pro.top().pro<=rest){now+=pro.top().pro;rest-=pro.top().pro;printf("%d %lld\n",pro.top().id,now);pro.pop();}if(pro.size()&&rest){Heapnode tmp=pro.top();pro.pop();tmp.pro-=rest;pro.push(tmp);}pro.push(a);now=a.rea;}int main(){int a,b,c,d;while(scanf("%d%d%d%d",&a,&b,&c,&d)==4)work((Heapnode){a,b,c,d});work((Heapnode){-1,inf,1,1});return 0;}


0 0
原创粉丝点击