大家写完代码准备交题的时候一定注意把自己的调试的代码注释掉
第一题 :
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// Scanner sc = new Scanner(System.in);
for (int i = 2022; i <= 100000; i ++ ) {
String s = Integer.toString(i, 16);
boolean f = false;
for (int j = 0; j < s.length(); j ++ ) {
if (!Character.isLetter(s.charAt(j))) {
f = true;
break;
}
}
if (f) continue;
System.out.println(i);
break;
}
System.out.println(Integer.toString(2730, 16));
}
}
第二题 :
public class Main2 {
public static void main(String[] args) {
String ans = "AAA";
for (int i = 1; i <= 1319; i ++ ) {
ans = add(ans);
}
System.out.println(ans);
}
public static String add(String s) {
char g = s.charAt(2);
char x = s.charAt(1);
char b = s.charAt(0);
StringBuilder sb = new StringBuilder(s);
if (g != 'Z') {
sb.setCharAt(2, (char) (g + 1));
return sb.toString();
} else if (x != 'Z') {
sb.setCharAt(2, 'A');
sb.setCharAt(1, (char) (x + 1));
return sb.toString();
} else if (b != 'z') {
sb.setCharAt(2, 'A');
sb.setCharAt(1, 'A');
sb.setCharAt(0, (char) (b + 1));
return sb.toString();
} else {
return "AAAA";
}
}
}
第三题 :
class Main3 {
// link : https://www.lanqiao.cn/problems/2408/learning/?problem_list_id=2&page=1&sort=students_count&tags=2023
public static void main(String[] args) {
int ans = 0;
for (int i = 1900_01_01; i <= 9999_12_31; i ++ ) {
if (check(i)) ans ++ ;
}
System.out.println(ans);
}
public static boolean check(int num) {
int y = num / 10000;
int m = num / 100 % 100;
int d = num % 100;
if (d == 0 || m == 0 || d > 31 || m > 12) return false;
boolean f = y % 400 == 0 || y % 100 != 0 && y % 4 == 0;
if ((m == 4 || m == 6 || m == 9 || m == 11) && d == 31) return false;
if (f && m == 2 && d > 29) return false;
if (!f && m == 2 && d > 28) return false;
int s1 = 0, s2 = 0;
while (y != 0) {
s1 += y % 10;
y /= 10;
}
while (m != 0) {
s2 += m % 10;
m /= 10;
}
while (d != 0) {
s2 += d % 10;
d /= 10;
}
return s1 == s2;
}
}
第四题 :
public class Main4 {
public static void main(String[] args) {
int ans = 0;
int[] arr = {99, 22, 51, 63, 72, 61, 20, 88, 40, 21, 63, 30, 11, 18, 99, 12, 93, 16, 7, 53, 64, 9, 28, 84, 34, 96, 52, 82, 51, 77};
// System.out.println(arr.length);
for (int i = 0; i < 30; i ++ ) {
for (int j = i + 1; j < 30; j ++ ) {
if (arr[i] * arr[j] >= 2022) ans ++ ;
}
}
System.out.println(ans);
}
}
第五题 :
public class Main5 {
static int ans = -1;
static int n, m;
static int now = 0;
static int[] dx = {0, 1, 0, -1};
static int[] dy = {1, 0, -1, 0};
static boolean[][] vis;
static String[] g = {
"110010000011111110101001001001101010111011011011101001111110",
"010000000001010001101100000010010110001111100010101100011110",
"001011101000100011111111111010000010010101010111001000010100",
"101100001101011101101011011001000110111111010000000110110000",
"010101100100010000111000100111100110001110111101010011001011",
"010011011010011110111101111001001001010111110001101000100011",
"101001011000110100001101011000000110110110100100110111101011",
"101111000000101000111001100010110000100110001001000101011001",
"001110111010001011110000001111100001010101001110011010101110",
"001010101000110001011111001010111111100110000011011111101010",
"011111100011001110100101001011110011000101011000100111001011",
"011010001101011110011011111010111110010100101000110111010110",
"001110000111100100101110001011101010001100010111110111011011",
"111100001000001100010110101100111001001111100100110000001101",
"001110010000000111011110000011000010101000111000000110101101",
"100100011101011111001101001010011111110010111101000010000111",
"110010100110101100001101111101010011000110101100000110001010",
"110101101100001110000100010001001010100010110100100001000011",
"100100000100001101010101001101000101101000000101111110001010",
"101101011010101000111110110000110100000010011111111100110010",
"101111000100000100011000010001011111001010010001010110001010",
"001010001110101010000100010011101001010101101101010111100101",
"001111110000101100010111111100000100101010000001011101100001",
"101011110010000010010110000100001010011111100011011000110010",
"011110010100011101100101111101000001011100001011010001110011",
"000101000101000010010010110111000010101111001101100110011100",
"100011100110011111000110011001111100001110110111001001000111",
"111011000110001000110111011001011110010010010110101000011111",
"011110011110110110011011001011010000100100101010110000010011",
"010011110011100101010101111010001001001111101111101110011101"
};
public static void main(String[] args) {
n = g.length; m = g[0].length();
vis = new boolean[n][m];
for (int i = 0; i < n; i ++ ) {
for (int j = 0; j < m; j ++ ) {
if (g[i].charAt(j) == '0' || vis[i][j]) continue;
dfs(i, j);
ans = Math.max(ans, now);
now = 0;
}
}
System.out.println(ans);
}
public static void dfs(int x, int y) {
now ++ ;
vis[x][y] = true;
for (int i = 0; i < 4; i ++ ) {
int a = x + dx[i], b = y + dy[i];
if (a < 0 || b < 0 || a >= n || b >= m || g[a].charAt(b) == '0' || vis[a][b]) continue;
dfs(a, b);
}
}
}
第六题 :
import java.util.Scanner;
public class Main6 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int w = sc.nextInt();
int n = sc.nextInt();
n %= 7; // ok
w -- ;
w = (w + n) % 7;
w ++ ;
System.out.println(w);
}
}
第七题 :
import java.util.Scanner;
public class Main7 {
static class PII {
int x, y;
public PII(int x, int y) {
this.x = x;
this.y = y;
}
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int w = sc.nextInt(), h = sc.nextInt(), n = sc.nextInt(), r = sc.nextInt();
PII[] p = new PII[n];
for (int i = 0; i < n; i ++ ) {
int x = sc.nextInt();
int y = sc.nextInt();
p[i] = new PII(x, y);
}
int ans = 0;
for (int i = 0; i <= w; i ++ ) {
for (int j = 0; j <= h; j ++ ) {
for (int k = 0; k < n; k ++ ) {
if (check(i, j, p[k], r)) {
ans ++ ;
break;
}
}
}
}
System.out.println(ans);
}
public static boolean check(int x, int y, PII p, int r) {
int a = p.x, b = p.y;
return (x - a) * (x - a) + (y - b) * (y - b) <= r * r;
}
}
第八题 :
import java.util.Scanner;
public class Main8 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int m = sc.nextInt();
int[][] d = new int[n + 10][m + 10];
// int[][] s = new int[n + 10][m + 10];
int t = sc.nextInt();
while (t -- > 0) {
int x = sc.nextInt(), y = sc.nextInt();
int a = sc.nextInt(), b = sc.nextInt();
d[x][y] -- ;
d[a + 1][y] ++ ;
d[x][b + 1] ++ ;
d[a + 1][b + 1] -- ;
}
for (int i = 1; i <= n; i ++ ) {
for (int j = 1; j <= m; j ++ ) {
d[i][j] = d[i][j] + d[i - 1][j] + d[i][j - 1] - d[i - 1][j - 1];
}
}
int ans = 0;
for (int i = 1; i <= n; i ++ ) {
for (int j = 1; j <= m; j ++ ) {
if (d[i][j] == 0) ans ++ ;
}
}
System.out.println(ans);
}
}
第九题 :
import java.util.Arrays;
import java.util.Scanner;
public class Main9 {
static int n, m;
static int[][] f;
static int[][] g;
static final int[] dx = {1, 0, -1, 0};
static final int[] dy = {0, 1, 0, -1};
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
n = sc.nextInt(); m = sc.nextInt();
f = new int[n][m];
g = new int[n][m];
for (int i = 0; i < n; i ++ ) Arrays.fill(f[i], -1);
for (int i = 0; i < n; i ++ ) {
for (int j = 0; j < m; j ++ ) {
g[i][j] = sc.nextInt();
}
}
int ans = -1;
for (int i = 0; i < n; i ++ ) {
for (int j = 0; j < m; j ++ ) {
ans = Math.max(ans, dfs_Meomery(i, j));
}
}
// for (int i = 0; i < n; i ++ ) {
// for (int j = 0; j < m; j ++ ) {
// System.out.print(f[i][j] + " ");
// }
// System.out.println();
// }
System.out.println(ans + 1);
}
public static int dfs_Meomery(int x, int y) {
if (f[x][y] != -1) return f[x][y];
f[x][y] = 0;
for (int i = 0; i < 4; i ++ ) {
int a = x + dx[i], b = y + dy[i];
if (a < 0 || a >= n || b < 0 || b >= m || g[x][y] <= g[a][b]) continue;
f[x][y] = Math.max(f[x][y], dfs_Meomery(a, b) + 1);
}
return f[x][y];
}
}
//4 5
//1 4 6 3 1
//11 8 7 3 1
//9 4 5 2 1
//1 3 2 2 1
第十题 :
//机器人判分系统要求必须如下规则:
// 1: 不能有package关键字
// 2: 类名必须是Main
import java.util.*;
public class Main10 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[] arr = new int[n];
for (int i = 0; i < n; i ++ ) {
arr[i] = sc.nextInt();
}
int k = sc.nextInt();
int[] newArr = new int[n + 2 * k];
for (int i = 0; i < n + 2 * k; i ++ ) {
if (i < k || i >= k + n) {
newArr[i] = 10000010;
}
else {
newArr[i] = arr[i - k];
}
}
int[] ans = minSlidingWindow(newArr, 2 * k + 1);
for (int i = 0; i < ans.length; i ++ ) {
System.out.print(ans[i] + " ");
}
}
public static int[] minSlidingWindow(int[] nums, int k) {
List<Integer> lis = new ArrayList<>();
Deque<Integer> deque = new ArrayDeque<>();
for (int i = 0; i < nums.length; i ++ ) {
while (!deque.isEmpty() && nums[deque.getLast()] > nums[i]) {
deque.removeLast();
}
deque.addLast(i);
if (i >= k - 1) {
while (!deque.isEmpty() && deque.getFirst() <= i - k) {
deque.removeFirst();
}
lis.add(nums[deque.getFirst()]);
}
}
int[] ans = new int[lis.size()];
for (int i = 0; i < ans.length; i ++ ) {
ans[i] = lis.get(i);
}
return ans;
}
}
第十一题 :
import java.util.Scanner;
public class Main11 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
double l = sc.nextDouble();
int ans = 0;
while (l > 1) {
l /= 2;
ans ++ ;
}
// System.out.println(l + " " + ans);
System.out.println(ans);
}
}
第十二题 :
import java.util.Scanner;
import java.util.Stack;
public class Main12 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String s = sc.next();
Stack<Character> sta = new Stack<>();
int m = sc.nextInt();
for (int i = 0; i < s.length(); i ++ ) {
if (m == 0) {
sta.add(s.charAt(i));
continue;
}
if (sta.isEmpty()) {
sta.add(s.charAt(i));
} else {
char x = s.charAt(i);
while (!sta.isEmpty() && x < sta.peek() && m > 0) {
sta.pop();
m -- ;
}
sta.add(x);
}
}
StringBuilder ans = new StringBuilder();
while (!sta.isEmpty()) {
ans.append(sta.pop());
}
ans.reverse();
System.out.println(ans);
}
}