1. 考察双向链表
  2. import java.io.IOException;
    import java.io.InputStreamReader;
    import java.io.StreamTokenizer;
    import java.util.LinkedList; public class Main {
    @SuppressWarnings("uncheck")
    public static void main(String[] args) throws IOException {
    StreamTokenizer st = new StreamTokenizer(new InputStreamReader(System.in));
    int n, m, k, q;
    st.nextToken();
    n = (int) st.nval;
    st.nextToken();
    m = (int) st.nval;
    st.nextToken();
    k = (int) st.nval;
    st.nextToken();
    q = (int) st.nval; LinkedList<int[]>[] queue = new LinkedList[n];
    for (int i = 0; i < n; i++) {
    queue[i] = new LinkedList<>();
    }
    int[][] time = new int[k + 1][2];
    int[] cost = new int[k];
    for (int i = 0; i < k; i++) {
    st.nextToken();
    int v = (int) st.nval;
    cost[i] = v;
    if (i < m * n) {
    if (queue[i % n].isEmpty()) {
    queue[i % n].add(new int[]{i, 0, v});
    time[i + 1] = new int[]{0, v};
    continue;
    }
    int[] last = queue[i % n].getLast();
    int finishedtime = last[2];
    queue[i % n].add(new int[]{i, finishedtime, finishedtime + v});
    time[i + 1] = new int[]{finishedtime, finishedtime + v};
    } else {
    int min = 1000_000_00;
    int minindex = -1;
    for (int j = 0; j < n; j++) {
    int[] first = queue[j].peekFirst();
    if (min > first[2]) {
    min = first[2];
    minindex = j;
    }
    }
    int[] last = queue[minindex].getLast();
    int finishedtime = last[2]; queue[minindex].pollFirst();
    queue[minindex].add(new int[]{i, finishedtime, finishedtime + v}); time[i + 1] = new int[]{finishedtime, finishedtime + v};
    }
    } int max = 540;
    for (int i = 1; i <= q; i++) {
    st.nextToken();
    int index = (int) st.nval;
    if (time[index][0] < max) {
    System.out.println(format(time[index][1]));
    } else {
    System.out.println("Sorry");
    }
    }
    } public static String format(int time) {
    int x = time / 60 + 8;
    int y = time % 60; StringBuilder sb = new StringBuilder();
    if (x < 10) {
    sb.append("0").append(x);
    } else {
    sb.append(x);
    }
    sb.append(":");
    if (y < 10) {
    sb.append("0").append(y);
    } else {
    sb.append(y);
    }
    return sb.toString();
    }
    }

PAT甲级【1014 Waiting in Line】的更多相关文章

  1. PAT甲级1014. Waiting in Line

    PAT甲级1014. Waiting in Line 题意: 假设银行有N个窗口可以开放服务.窗前有一条黄线,将等候区分为两部分.客户要排队的规则是: 每个窗口前面的黄线内的空间足以包含与M个客户的一 ...

  2. PAT 甲级 1014 Waiting in Line (30 分)(queue的使用,模拟题,有个大坑)

    1014 Waiting in Line (30 分)   Suppose a bank has N windows open for service. There is a yellow line ...

  3. PAT A 1014. Waiting in Line (30)【队列模拟】

    题目:https://www.patest.cn/contests/pat-a-practise/1014 思路: 直接模拟类的题. 线内的各个窗口各为一个队,线外的为一个,按时间模拟出队.入队. 注 ...

  4. PAT甲级——A1014 Waiting in Line

    Suppose a bank has N windows open for service. There is a yellow line in front of the windows which ...

  5. PAT 1014 Waiting in Line (模拟)

    1014. Waiting in Line (30) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Suppo ...

  6. 1014 Waiting in Line (30分)

    1014 Waiting in Line (30分)   Suppose a bank has N windows open for service. There is a yellow line i ...

  7. PTA (Advanced Level) 1014 Waiting in Line

    Waiting in Line Suppose a bank has N windows open for service. There is a yellow line in front of th ...

  8. 【PAT甲级】1014 Waiting in Line (30 分)(队列维护)

    题面: 输入四个正整数N,M,K,Q(N<=20,M<=10,K,Q<=1000),N为银行窗口数量,M为黄线内最大人数,K为需要服务的人数,Q为查询次数.输入K个正整数,分别代表每 ...

  9. PAT 1014. Waiting in Line

    Suppose a bank has N windows open for service.  There is a yellow line in front of the windows which ...

  10. PAT 1014 Waiting in Line (模拟)

    Suppose a bank has N windows open for service. There is a yellow line in front of the windows which ...

随机推荐

  1. 问题:Duplicate报错RMAN-03009, ORA-17628, ORA-19505

    前面文章提到,这周末帮一个客户测试报错场景: 客户通过duplicate生产备库的方式创建cascade备库. 发现每次都会遇到两个文件报错,ORA-17628: Oracle error 19505 ...

  2. Spring Boot 参数校验注解(自整理,不停的测试更新)

    首先我们只使用java官方的 javax.validation.constraints ,足以使用了,不使用spring boot 自身的,自身的与官方的一致,可能会有扩展,但是还得引入包,麻烦,只用 ...

  3. 使用了未经检查或不安全的操作。 有关详细信息, 请使用 -Xlint:unchecked 重新编译

  4. ubuntu之jupyter notebook配置

    ubuntu之jupyter notebook配置 安装jupyter: 前提:安装pip pip install jupyter jupyter notebook 配置: 生成配置文件: jupyt ...

  5. NC16641 [NOIP2007]守望者的逃离

    题目链接 题目 题目描述 恶魔猎手尤迪安野心勃勃,他背叛了暗夜精灵,率领深藏在海底的娜迦族企图叛变.守望者在与尤迪安的交锋中遭遇了围杀,被困在一个荒芜的大岛上.为了杀死守望者,尤迪安开始对这个荒岛施咒 ...

  6. Ubuntu20.04和22.04离线安装PostgreSQL14

    今天安装 Postgresql14 遇到一个问题, 目标服务器只有内网, 内网提供标准的apt仓库, 但是因为不能连接外网, 所以没法添加第三方仓库, 这样安装pg14就成了问题. 从pg的官网看, ...

  7. 【Unity3D】异步Socket通讯

    1 前言 ​ 同步 Socket 通讯 中的 Accept.Connect.Receive 等方法会阻塞当前线程,当前线程必须等待这些方法执行完,才会继续往下执行,用户需要另开线程执行这些耗时方法,否 ...

  8. Laravel入坑指南(10)——事件Event

    不知不觉,我们已经来到了第10小节.这一小节,我们一起讨论关于"事件"这个话题.众所周知,从二进制到汇编,再到高等级语言,这一路发展下来,代码都是顺序执行的,那么事件是什么?这个事 ...

  9. 配置nginx反向代理

    最近在做一个前后分离的项目,前端用Vue,后台spring boot,使用nginx做反向代理.下面说一下如何配置: 启动spring boot项目,端口8110 启动nginx 修改nginx.co ...

  10. win32 - 使用Desktop Duplication API复制桌面图像

    该代码来源于codeproject,经过测试发现,在屏幕处于旋转的情况下捕获的图像是黑色的.暂时没有找到原因. 代码开箱即用, #define WIN32_LEAN_AND_MEAN #include ...