zoukankan      html  css  js  c++  java
  • BZOJ 1216: [HNOI2003]操作系统( 优先队列 )

    按题意用priority_queue模拟即可 

    ----------------------------------------------------------------------

    #include<bits/stdc++.h>
    using namespace std;
    const int maxn = 1009;
    const int MOD = 10000;
    struct Node {
    int x, w, v;
    bool operator < (const Node &o) const {
    return v < o.v || (v == o.v && x > o.x);
    }
    };
    priority_queue<Node> Q;
    int cur;
    void work(int x, int t, int w, int v, bool tag = true) {
    if(!Q.empty()) {
    while(!Q.empty()) {
    Node o = Q.top();
    if(t - cur >= o.w) {
    cur += o.w;
    printf("%d %d ", o.x, cur);
    Q.pop();
    } else {
    int _x = o.x, _w = o.w - t + cur, _v = o.v;
    Q.pop();
    Q.push((Node) {_x, _w, _v});
    cur = t;
    break;
    }
    }
    if(Q.empty())
    cur = t;
    } else 
    cur = t;
    if(tag) Q.push((Node) {x, w, v});
    }
    int main() {
    int x, t, w, v;
    while(scanf("%d%d%d%d", &x, &t, &w, &v) == 4) work(x, t, w, v);
    work(0, 1000000000, 0, 0, 0);
    return 0;
    }

    ---------------------------------------------------------------------- 

    1216: [HNOI2003]操作系统

    Time Limit: 10 Sec  Memory Limit: 162 MB
    Submit: 514  Solved: 280
    [Submit][Status][Discuss]

    Description

    写一个程序来模拟操作系统的进程调度。假设该系统只有一个CPU,每一个进程的到达时间,执行时间和运行优先级都是已知的。其中运行优先级用自然数表示,数字越大,则优先级越高。如果一个进程到达的时候CPU是空闲的,则它会一直占用CPU直到该进程结束。除非在这个过程中,有一个比它优先级高的进程要运行。在这种情况下,这个新的(优先级更高的)进程会占用CPU,而老的只有等待。如果一个进程到达时,CPU正在处理一个比它优先级高或优先级相同的进程,则这个(新到达的)进程必须等待。一旦CPU空闲,如果此时有进程在等待,则选择优先级最高的先运行。如果有多个优先级最高的进程,则选择到达时间最早的。

    Input

    输入文件包含若干行,每一行有四个自然数(均不超过108),分别是进程号,到达时间,执行时间和优先级。不同进程有不同的编号,不会有两个相同优先级的进程同时到达。输入数据已经按到达时间从小到大排序。输入数据保证在任何时候,等待队列中的进程不超过15000个。

    Output

    按照进程结束的时间输出每个进程的进程号和结束时间

    Sample Input

    1 1 5 3
    2 10 5 1
    3 12 7 2
    4 20 2 3
    5 21 9 4
    6 22 2 4
    7 23 5 2
    8 24 2 4

    Sample Output

    1 6
    3 19
    5 30
    6 32
    8 34
    4 35
    7 40
    2 42

    HINT

    Source

  • 相关阅读:
    14.3.2.1 Transaction Isolation Levels 事务隔离级别
    ReentrantLock可重入锁
    Lock与synchronized 的区别
    synchronized 与 Lock
    This usually indicates a missing no-arg constructor or that the editor's class name was mistyped in
    Oracle dump 分析secondary key
    java.lang.ClassNotFoundException: org.springframework.web.util.IntrospectorCleanupListener
    Oracle 验证IOT表数据存储在主键里
    Cause: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for U
    Oracle heap 表的主键 dump 分析
  • 原文地址:https://www.cnblogs.com/JSZX11556/p/4840932.html
Copyright © 2011-2022 走看看