public static void main(String[] args) { int[] a = new int[17]; Scanner in = new Scanner(System.in); int n = in.nextInt(), m = in.nextInt(); int sum = 7 * n, count = 0; while(sum >= 0){ //计算每7个相邻元素中至少需要几个负数才能相加小于0 sum = sum - n + m; count++; } //count < 5时,只需要考虑为头尾两个相邻对的负数个数 //count >= 5时,还需加上中间相邻对中三个元素中负数的个数。 if(count >= 5){ System.out.println((3 * count - 4) * m + (17 - (3 * count - 4)) * n); } else System.out.println(2 * count * m + (17 - 2 * count) * n); } 格式有点乱,将就看吧,17数的AC
点赞 评论

相关推荐

02-16 01:39
南昌大学 Java
重剑Ds:感觉不太可能 后端都减飞了 根本不缺人
点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务