第一题:全球变暖
// 1:无需package
// 2: 类名必须Main, 不可修改
import java.util.Scanner;
public class Main {
static int N = 1010;
static char[][] g = new char[N][N];
static boolean[][] st = new boolean[N][N];
static int[] dx = {1, 0, -1, 0};
static int[] dy = {0, -1, 0, 1};
static long cnt1, cnt2;
static int n;
public static boolean check(int x, int y){
if(x >= 1 && x <= n && y >= 1 && y <= n) return true;
return false;
}
public static void dfs(int x, int y){
cnt1++;
boolean flag = true;
for(int i = 0; i < 4; i++){
int xx = x + dx[i], yy = y + dy[i];
if(check(xx, yy)){
if(g[xx][yy] == '.' && flag){
flag = false;
}else if(g[xx][yy] == '#' && !st[xx][yy]){
st[xx][yy] = true;
dfs(xx, yy);
}
}
}
if(!flag) cnt2++;
}
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
n = s.nextInt();
s.nextLine();
for(int i = 1; i <= n; i++){
String str = s.nextLine();
for(int j = 1; j <= n; j++){
g[i][j] = str.charAt(j-1);
}
}
// for (int i = 1; i <= n; i++) {
// for (int j = 1; j <= n; j++) {
// System.out.print(g[i][j]);
// }
// System.out.println();
// }
long res = 0;
for(int i = 1; i <= n; i++){
for(int j = 1; j <= n; j++){
if(g[i][j] == '#' && !st[i][j]){
st[i][j] = true;
cnt1 = 0; cnt2 = 0;
dfs(i, j);
if(cnt1 == cnt2){
res++;
}
}
}
}
System.out.println(res);
}
}
第二题:调手表
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Queue;
public class Main {
static int N = (int)1e5 + 10;
static int[] dist = new int[N];
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] s = br.readLine().split(" ");
int n = Integer.parseInt(s[0]);
int k = Integer.parseInt(s[1]);
Arrays.fill(dist, 0x3f3f3f3f);
Queue<Integer> q = new LinkedList<>();
dist[0] = 0;
int res = 0;
q.add(0);
while(!q.isEmpty()){
int t = q.poll();
res = Math.max(res, dist[t]);
if(dist[(t+1)%n] == 0x3f3f3f3f){
dist[(t+1)%n] = dist[t]+1;
q.add((t+1)%n);
}
if(dist[(t+k)%n] == 0x3f3f3f3f){
dist[(t+k)%n] = dist[t] + 1;
q.add((t+k)%n);
}
}
System.out.println(res);
}
}
第三题:铺设道路
补题----------------------------------------
第四题:搬砖
补题-----------------------------------------------
补了发评论区