感觉其他人的java代码写的好复杂,就贴出来短一些的供参考
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
int m, current, temp, sum = 0, cutTreeNum = 0, t3Num = 0;
boolean[] vis = new boolean[n + 5];
for (int i = 0; i < n; i++) {
m = scanner.nextInt();
current = scanner.nextInt();
for (int j = 1; j < m; j++) {
temp = scanner.nextInt();
if (temp <= 0) {
current += temp;
} else if (current > temp) {
current = temp;
vis[i] = true;
}
}
sum += current;
}
for (int i = 0; i < n; i++) {
if (vis[i])
cutTreeNum++;
if (vis[(i - 2 + n) % n] && vis[(i - 1 + n) % n] && vis[i])
t3Num++;
}
System.out.println(sum + " " + cutTreeNum + " " + t3Num);
}
}