小明种苹果(续)

假装没事ソ 提交于 2019-12-04 16:38:10

 

问题描述:



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);
    }
}

 

 

 

 

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!