zoukankan      html  css  js  c++  java
  • P2278 [HNOI2003]操作系统

    模拟

    思路挺好想的,就是模拟

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

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

    代码

    #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 ;
    }
    

    溜了溜了

  • 相关阅读:
    mysql索引需要了解的几个注意
    apache配置--虚拟目录
    简化LINUX的命令输入 简化linux命令 快捷键 短路径
    apache vhost 访问权限配置
    php中常用设置
    win7配置nginx + php
    restful php
    php 笔记 汇总 学习
    mysql修改表结构
    mysql 优化工具
  • 原文地址:https://www.cnblogs.com/lyt020321/p/11402317.html
Copyright © 2011-2022 走看看