题目 3158: 三国游戏

题目描述:

小蓝正在玩一款游戏。游戏中魏蜀吴三个国家各自拥有一定数量的士兵X, Y, Z (一开始可以认为都为 0 )。游戏有 n 个可能会发生的事件,每个事件之间相互独立且最多只会发生一次,当第 i 个事件发生时会分别让 X, Y, Z 增加Ai , Bi ,Ci 。

当游戏结束时 (所有事件的发生与否已经确定),如果 X, Y, Z 的其中一个大于另外两个之和,我们认为其获胜。例如,当 X > Y + Z 时,我们认为魏国获胜。小蓝想知道游戏结束时如果有其中一个国家获胜,最多发生了多少个事件?

如果不存在任何能让某国获胜的情况,请输出 −1 。

代码:

package lanqiao;

import java.math.BigInteger;
import java.util.*;

public class Main {
    public static void main(String[] args) {
       Scanner sc = new Scanner(System.in);
       int n = sc.nextInt();
       int[] a = new int[n];
       int[] b = new int[n];
       int[] c = new int[n];
       for(int i = 0;i < n;i ++)
       {
           a[i] = sc.nextInt();
       }
       for(int i = 0;i < n;i ++)
       {
           b[i] = sc.nextInt();
       }
       for(int i = 0;i < n;i ++)
       {
           c[i] = sc.nextInt();
       }

       for(int i = 0;i <n;i ++)
       {
           int m = a[i],e = b[i],f = c[i];
           a[i] = m - e - f;
           b[i] = e - m - f;
           c[i] = f - m - e;
       }
       Arrays.sort(a);
       Arrays.sort(b);
       Arrays.sort(c);
       int d = -1;

       long sum = 0,sun = 0,sus = 0;
       for(int i = n - 1;i >= 0;i --)
       {
           sum += a[i];
           sun += b[i];
           sus += c[i];
           if(sum > 0 || sun > 0 || sus > 0){
               d = n - i;
           }
       }
        System.out.println(d);
    }
}

相关推荐

  1. 题目 3158: 游戏

    2024-04-08 22:58:01       14 阅读
  2. 游戏.

    2024-04-08 22:58:01       22 阅读
  3. 第十四届蓝桥杯C组题目 游戏

    2024-04-08 22:58:01       40 阅读
  4. AcWing:4965. 游戏

    2024-04-08 22:58:01       40 阅读
  5. 蓝桥杯---游戏

    2024-04-08 22:58:01       35 阅读
  6. 蓝桥集训之游戏

    2024-04-08 22:58:01       45 阅读
  7. 题目 3150: 冶炼金属

    2024-04-08 22:58:01       24 阅读
  8. 游戏(第十四届蓝桥杯)

    2024-04-08 22:58:01       33 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-04-08 22:58:01       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-04-08 22:58:01       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-04-08 22:58:01       18 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-04-08 22:58:01       20 阅读

热门阅读

  1. Azure AI 新发布了 9 种更逼真的对话 AI 声音

    2024-04-08 22:58:01       16 阅读
  2. 动态规划(2)

    2024-04-08 22:58:01       14 阅读
  3. 汇编语言和C语言得优势和劣势简析

    2024-04-08 22:58:01       24 阅读
  4. 备战蓝桥杯---最长上升子序列(LIS)模板

    2024-04-08 22:58:01       19 阅读
  5. python实现3d建模

    2024-04-08 22:58:01       13 阅读
  6. 设计模式 工厂模式

    2024-04-08 22:58:01       11 阅读
  7. MySQL 中,常见的 JOIN 查询语句

    2024-04-08 22:58:01       13 阅读