提交 c304bf85 编写于 作者: qq_36480062's avatar qq_36480062

commit

上级 30eb9dfb
......@@ -52,7 +52,7 @@ public class 修计算机 {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();//计算机数量
int d = sc.nextInt();//可通信距离
UnionFindE u = new UnionFindE(n);
UnionFind u = new UnionFind(n);
dx = new int[n];
dy = new int[n];
ArrayList<Integer> list = new ArrayList<>();//已经修好的计算机
......@@ -88,31 +88,4 @@ public class 修计算机 {
public static double dis(int a, int b) {
return Math.sqrt(Math.abs((dx[a] - dx[b])) * Math.abs((dx[a] - dx[b])) + Math.abs((dy[a] - dy[b])) * Math.abs((dy[a] - dy[b])));
}
}
class UnionFindE {
private int[] parent;
UnionFindE(int n) {
parent = new int[n + 1];
for (int i = 0; i < n + 1; i++) {
parent[i] = i;
}
}
public void Union(int p, int q) {
int pRoot = find(p);
int qRoot = find(q);
if (pRoot != qRoot) {
parent[pRoot] = qRoot;
}
}
public int find(int p) {
while (p != parent[p]) {
p = find(parent[p]);
}
return parent[p];
}
}
}
\ No newline at end of file
package com.shiyu;
public class tsdt {
public static void main(String[] args) {
for (int i = 0; i < 4; i++) {
System.out.println(i);
}
}
}
......@@ -61,7 +61,9 @@ public class 做作业 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int s = sc.nextInt();
for (int i = 0; i < s; i++) {
}
}
}
//#include<stdio.h>
......
......@@ -14,7 +14,7 @@ import java.util.Scanner;
*/
public class 卖商品 {
static class Node {
int profit;
int profit;//价值
int deadline;
public int getProfit() {
......@@ -56,12 +56,24 @@ public class 卖商品 {
for (int i = 0; i < count; i++) {
list.add(new Node(sc.nextInt(), sc.nextInt()));
}
list.sort((o1, o2) -> o2.profit - o1.profit);
boolean[] visit = new boolean[count];
System.out.println(list);
list.add(0, new Node(1, 1));
list.sort((o1, o2) -> o2.profit - o1.profit);//按照商品价格从大到小排列
boolean[] visit = new boolean[1000];
for (int i = 1; i <= count; i++) {
if (!visit[list.get(i).deadline]) {//如果这一天没有被占用
maxProfit += list.get(i).profit;//要了这一天
visit[list.get(i).deadline] = true;//占用这一天
} else {
for (int j = list.get(i).deadline - 1; j >= 1; j--) {
if (!visit[j]) {
maxProfit += list.get(i).profit;
visit[j] = true;
break;
}
}
}
}
System.out.println(maxProfit);
}
}
/**
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册