201909-2 小明种苹果(续) Java

201909-2  小明种苹果(续) Java

思路:
待补充

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[][] count = new int[n][1001];
        int size[] = new int[n];
        for(int i = 0; i < n; i++) {
            int m = sc.nextInt();
            size[i] = m;
            for(int j = 0; j < m; j++) {
                count[i][j] = sc.nextInt();
            }
        }
        
        int[] sum = new int[n];
        int[] del = new int[n];
        int allSum = 0;
        for(int i = 0; i < n; i++) {
            sum[i] = count[i][0];
            for(int j = 1; j < size[i]; j++) {
                if(count[i][j] > 0) {
                    if(sum[i] != count[i][j]) {
                        del[i] = 1;
                    }
                    sum[i] = count[i][j];
                }else {
                    sum[i] += count[i][j];
                }
                
            }
            allSum += sum[i];
        }
        int delCount = 0;
        int group = 0;
        for(int i = 0; i < n; i++) {
            if(del[i] != 0) {
                delCount ++;
                if(i == 0) {
                    if(del[n-1] != 0 && del[i+1] != 0) {
                        group ++;
                    }
                }else if(i == n-1) {
                    if(del[i-1] != 0 && del[0] != 0) {
                        group ++;
                    }
                }else {
                    if(del[i-1] != 0 && del[i+1] != 0) {
                        group ++;
                    }
                }
            }
        }
        System.out.println(allSum+" "+delCount+" "+group);
    }
}

201909-2 小明种苹果(续) Java

上一篇:模仿虎牙App 导航栏切换


下一篇:Enable VT-x in your BIOS security settings, ensure that HAXM is installed properly. Try disabling 3rd party security software if the problem still occurs