ccf公共钥匙盒python_CCF/CSP 公共钥匙盒

无情的copy机器...

【解题思路】:排序+模拟

【代码如下】:

import java.util.*;

public class Main {

public static void main(String[] args) {

new Main().solve();

}

public void solve() {

Scanner sc = new Scanner(System.in);

int n = sc.nextInt(),k = sc.nextInt();

int[] key = new int[n+1];

for (int i=0; i<=n; i++) {

key[i] = i;

}

Node[] nodes = new Node[k];

for (int i=0; i

int a = sc.nextInt();

int b = sc.nextInt();

int c = sc.nextInt();

nodes[i] = new Node(a, b, b+c);

}

Node[] start = nodes.clone();

Node[] end = nodes.clone();

Arrays.sort(start, (o1, o2) -> {

if (o1.s == o2.s) return o1.w - o2.w;

return o1.s - o2.s;

});

Arrays.sort(end, (o1, o2) -> {

if (o1.c == o2.c) return o1.w - o2.w;

return o1.c - o2.c;

});

int t = 0,s = 0,e = 0;

while (t++ < 10101) {

for (; e< end.length; e++) {

if (t

if (t == end[e].c)

unUse(end[e].w, key);

}

for (; s< start.length; s++) {

if (t

if (t == start[s].s)

use(start[s].w, key);

}

if (e== end.length && s == start.length) break;

}

for (int i=1; i<=n; i++) {

System.out.print(key[i]);

if (i != n) System.out.print(" ");

}

System.out.println();

}

public void use(int tar,int [] key) {

for (int i=0; i< key.length; i++) {

if (key[i] == tar) {

key[i] = -1;

break;

}

}

}

public void unUse(int tar, int[] key) {

for (int i=0; i< key.length; i++) {

if (key[i] == -1) {

key[i] = tar;

break;

}

}

}

class Node {

public int w;

public int s;

public int c;

public Node(int w,int s,int c) {

this.w = w;

this.s = s;

this.c = c;

}

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值