已交
This commit is contained in:
+5
-1
@@ -22,4 +22,8 @@ output/
|
||||
Thumbs.db
|
||||
|
||||
# 排除竞赛平台配置文件
|
||||
.cph/
|
||||
.cph/
|
||||
|
||||
# 排除作业相关目录
|
||||
作业/刘航宇-day*
|
||||
作业/提交/
|
||||
|
||||
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.
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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
Scanner in = new Scanner(System.in);
|
||||
if (in.hasNextLine()) {
|
||||
String s1 = in.nextLine();
|
||||
if (in.hasNextLine()) {
|
||||
String s2 = in.nextLine();
|
||||
|
||||
String longer, shorter;
|
||||
if (s1.length() >= s2.length()) {
|
||||
longer = s1;
|
||||
shorter = s2;
|
||||
} else {
|
||||
longer = s2;
|
||||
shorter = s1;
|
||||
}
|
||||
|
||||
// 将短的字符串内容覆盖到长的字符串内(从头开始)
|
||||
StringBuilder sb = new StringBuilder(longer);
|
||||
for (int i = 0; i < shorter.length(); i++) {
|
||||
sb.setCharAt(i, shorter.charAt(i));
|
||||
}
|
||||
|
||||
System.out.println(sb.toString());
|
||||
}
|
||||
}
|
||||
in.close();
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 2.8 MiB |
@@ -0,0 +1,32 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
Scanner in = new Scanner(System.in);
|
||||
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);
|
||||
}
|
||||
in.close();
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 2.8 MiB |
@@ -0,0 +1,39 @@
|
||||
import java.util.Arrays;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
Scanner in = new Scanner(System.in);
|
||||
if (in.hasNextInt()) {
|
||||
int n = in.nextInt();
|
||||
int t = in.nextInt();
|
||||
|
||||
int[] a = new int[n];
|
||||
for (int i = 0; i < n; i++) {
|
||||
a[i] = in.nextInt();
|
||||
}
|
||||
|
||||
int[] b = new int[n];
|
||||
for (int i = 0; i < n; i++) {
|
||||
b[i] = in.nextInt();
|
||||
}
|
||||
|
||||
// 贪心策略:将 A 升序排序,B 升序排序
|
||||
// 然后将 A 中最小的与 B 中最大的配对
|
||||
Arrays.sort(a);
|
||||
Arrays.sort(b);
|
||||
|
||||
long totalOvertime = 0;
|
||||
for (int i = 0; i < n; i++) {
|
||||
// A[i] 配对 B[n - 1 - i]
|
||||
int time = a[i] + b[n - 1 - i];
|
||||
if (time > t) {
|
||||
totalOvertime += (time - t);
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println(totalOvertime);
|
||||
}
|
||||
in.close();
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 2.8 MiB |
Binary file not shown.
|
After Width: | Height: | Size: 2.8 MiB |
@@ -0,0 +1,106 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
public class Main {
|
||||
static final long MOD = 1000000007;
|
||||
static long[] powerOf10;
|
||||
static Node[][][] memo;
|
||||
static int[] digits;
|
||||
|
||||
static class Node {
|
||||
long cnt;
|
||||
long sum;
|
||||
long sqSum;
|
||||
|
||||
public Node(long c, long s, long sq) {
|
||||
this.cnt = c;
|
||||
this.sum = s;
|
||||
this.sqSum = sq;
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
Scanner in = new Scanner(System.in);
|
||||
// 初始化10的幂次
|
||||
powerOf10 = new long[20];
|
||||
powerOf10[0] = 1;
|
||||
for (int i = 1; i < 20; i++) {
|
||||
powerOf10[i] = (powerOf10[i - 1] * 10) % MOD;
|
||||
}
|
||||
|
||||
if (in.hasNextLong()) {
|
||||
long l = in.nextLong();
|
||||
long r = in.nextLong();
|
||||
long ans = (solve(r) - solve(l - 1) + MOD) % MOD;
|
||||
System.out.println(ans);
|
||||
}
|
||||
in.close();
|
||||
}
|
||||
|
||||
static long solve(long n) {
|
||||
if (n == 0)
|
||||
return 0;
|
||||
String s = String.valueOf(n);
|
||||
int len = s.length();
|
||||
digits = new int[len];
|
||||
for (int i = 0; i < len; i++) {
|
||||
digits[i] = s.charAt(len - 1 - i) - '0';
|
||||
}
|
||||
|
||||
// 重置memo
|
||||
memo = new Node[len + 1][7][7];
|
||||
|
||||
Node res = dfs(len - 1, 0, 0, true);
|
||||
return res.sqSum;
|
||||
}
|
||||
|
||||
static Node dfs(int pos, int valRem, int sumRem, boolean limit) {
|
||||
if (pos < 0) {
|
||||
// 如果数字本身不是7的倍数,且各位数字之和不是7的倍数,则有效
|
||||
// (含7的情况已在循环中跳过)
|
||||
if (valRem != 0 && sumRem != 0) {
|
||||
return new Node(1, 0, 0);
|
||||
}
|
||||
return new Node(0, 0, 0);
|
||||
}
|
||||
if (!limit && memo[pos][valRem][sumRem] != null) {
|
||||
return memo[pos][valRem][sumRem];
|
||||
}
|
||||
|
||||
int up = limit ? digits[pos] : 9;
|
||||
long cnt = 0;
|
||||
long sum = 0;
|
||||
long sqSum = 0;
|
||||
|
||||
for (int d = 0; d <= up; d++) {
|
||||
if (d == 7)
|
||||
continue; // 跳过含7的情况
|
||||
|
||||
Node next = dfs(pos - 1, (valRem * 10 + d) % 7, (sumRem + d) % 7, limit && (d == up));
|
||||
|
||||
if (next.cnt > 0) {
|
||||
long p = powerOf10[pos];
|
||||
long val = (d * p) % MOD;
|
||||
long val2 = (val * val) % MOD;
|
||||
|
||||
// 更新计数
|
||||
cnt = (cnt + next.cnt) % MOD;
|
||||
|
||||
// 更新和: sum += next.sum + val * next.cnt
|
||||
long termSum = (val * next.cnt) % MOD;
|
||||
sum = (sum + next.sum + termSum) % MOD;
|
||||
|
||||
// 更新平方和: sqSum += next.sqSum + 2 * val * next.sum + val^2 * next.cnt
|
||||
long termSq1 = next.sqSum;
|
||||
long termSq2 = (2 * val % MOD * next.sum) % MOD;
|
||||
long termSq3 = (val2 * next.cnt) % MOD;
|
||||
sqSum = (sqSum + termSq1 + termSq2 + termSq3) % MOD;
|
||||
}
|
||||
}
|
||||
|
||||
Node res = new Node(cnt, sum, sqSum);
|
||||
if (!limit) {
|
||||
memo[pos][valRem][sumRem] = res;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 2.8 MiB |
@@ -0,0 +1,18 @@
|
||||
import java.util.Scanner;
|
||||
import java.math.BigInteger;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
Scanner in = new Scanner(System.in);
|
||||
if (in.hasNext()) {
|
||||
String s1 = in.next();
|
||||
if (in.hasNext()) {
|
||||
String s2 = in.next();
|
||||
BigInteger a = new BigInteger(s1);
|
||||
BigInteger b = new BigInteger(s2);
|
||||
System.out.println(a.add(b));
|
||||
}
|
||||
}
|
||||
in.close();
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 2.7 MiB |
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.
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.
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.
Reference in New Issue
Block a user