已交
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+21
-32
@@ -3,41 +3,30 @@ import java.util.Scanner;
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
Scanner in = new Scanner(System.in);
|
||||
int n = in.nextInt();
|
||||
int[] mention = new int[101];
|
||||
boolean[][] by = new boolean[101][101];
|
||||
for (int i = 0; i < n; i++) {
|
||||
int sender = in.nextInt();
|
||||
int k = in.nextInt();
|
||||
for (int j = 0; j < k; j++) {
|
||||
int id = in.nextInt();
|
||||
if (id >= 0 && id <= 100) {
|
||||
mention[id]++;
|
||||
if (sender >= 0 && sender <= 100)
|
||||
by[id][sender] = true;
|
||||
if (in.hasNextInt()) {
|
||||
int n = in.nextInt();
|
||||
int[] arr = new int[n];
|
||||
for (int i = 0; i < n; i++) {
|
||||
arr[i] = in.nextInt();
|
||||
}
|
||||
|
||||
// 题目要求计算最少交换次数,即逆序对的数量
|
||||
// 使用冒泡排序的交换次数来统计
|
||||
int swaps = 0;
|
||||
for (int i = 0; i < n - 1; i++) {
|
||||
for (int j = 0; j < n - 1 - i; j++) {
|
||||
if (arr[j] > arr[j + 1]) {
|
||||
// 交换
|
||||
int temp = arr[j];
|
||||
arr[j] = arr[j + 1];
|
||||
arr[j + 1] = temp;
|
||||
swaps++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println(swaps);
|
||||
}
|
||||
int bestId = 0;
|
||||
int bestCount = -1;
|
||||
for (int id = 0; id <= 100; id++) {
|
||||
if (mention[id] > bestCount) {
|
||||
bestCount = mention[id];
|
||||
bestId = id;
|
||||
}
|
||||
}
|
||||
System.out.println(bestId);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
boolean first = true;
|
||||
for (int s = 0; s <= 100; s++) {
|
||||
if (by[bestId][s]) {
|
||||
if (!first)
|
||||
sb.append(' ');
|
||||
sb.append(s);
|
||||
first = false;
|
||||
}
|
||||
}
|
||||
System.out.println(sb.toString());
|
||||
in.close();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user