首页 > 代码库 > BZOJ 1216 操作系统(堆)
BZOJ 1216 操作系统(堆)
用堆模拟题目中的操作即可。
# include <cstdio> # include <cstring> # include <cstdlib> # include <iostream> # include <vector> # include <queue> # include <stack> # include <map> # include <set> # include <cmath> # include <algorithm> using namespace std; # define lowbit(x) ((x)&(-x)) # define pi acos(-1.0) # define eps 1e-9 # define MOD 1000000000 # define INF 1000000000 # define mem(a,b) memset(a,b,sizeof(a)) # define FOR(i,a,n) for(int i=a; i<=n; ++i) # define FO(i,a,n) for(int i=a; i<n; ++i) # define bug puts("H"); # define lch p<<1,l,mid # define rch p<<1|1,mid+1,r # define mp make_pair # define pb push_back typedef pair<int,int> PII; typedef vector<int> VI; # pragma comment(linker, "/STACK:1024000000,1024000000") typedef long long LL; int Scan() { int x=0,f=1;char ch=getchar(); while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();} while(ch>=‘0‘&&ch<=‘9‘){x=x*10+ch-‘0‘;ch=getchar();} return x*f; } void Out(int a) { if(a<0) {putchar(‘-‘); a=-a;} if(a>=10) Out(a/10); putchar(a%10+‘0‘); } const int N=20005; //Code begin... struct node{ int id, to, t, now, level; node(int _id=0, int _to=0, int _t=0, int _level=0):id(_id),to(_to),t(_t),level(_level){} bool operator <(const node&r)const{ if (level!=r.level) return level<r.level; return to>r.to; } }; priority_queue<node>que; int main () { node tmp; int id, to, t, level, f=0; while (~scanf("%d%d%d%d",&id,&to,&t,&level)) { while (!que.empty()) { tmp=que.top(); que.pop(); if (tmp.t<=to-f) f+=tmp.t, printf("%d %d\n",tmp.id,f); else {tmp.t-=(to-f); que.push(tmp); break;} } f=to; que.push(node(id,to,t,level)); } while (!que.empty()) { tmp=que.top(); que.pop(); f+=tmp.t; printf("%d %d\n",tmp.id,f); } return 0; }
BZOJ 1216 操作系统(堆)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。