codeforces gym 100694 M The Fifth Season 巴什博弈扩展 Java
来源:互联网 发布:优酷怎么在mac下缓存 编辑:程序博客网 时间:2024/06/03 20:53
巴什博弈扩展题,难度稍有加大。
博弈扩展详情参考:ACM 数论篇——博弈论
import java.io.BufferedReader;import java.io.BufferedWriter;import java.io.InputStreamReader;import java.io.OutputStreamWriter;import java.io.PrintWriter;import java.util.Scanner;/** * 题意:coinsSum 个金币,两个人轮流取,一共有 rounds 回合,每回合给定取金币的数目范围[oneMinMove,oneMaxMove], * 假设两个人的取法都为最佳(即向着自己赢的目标取),问每个回合中,两人一共最多能取多少次。 * * 分析:巴什博弈扩展。 * * 解决方案:一共分为以下四种情况:其中 k = coinsSum / (oneMinMove+oneMaxMove) * ①、当 coinsSum = (oneMinMove+oneMaxMove) * k (k 为任意整数)时,后手胜。ans = k * 2 * ②、当 coinsSum = (oneMinMove+oneMaxMove) * k + s(k 为任意整数)时,对 s 分以下情况: * i、当 s ∈ [1,oneMinMove) 时,后手胜。因为后手取完之后,剩余的金币数量小于 oneMinMove,导致先手无法再取金币。 * ans = k * 2 * ii、当 s ∈ [oneMinMove,oneMaxMove] 时,先手最后可以取光而获胜。 * ans = k * 2 + 1. 其中 +1 是因为先手最后比后手多取一次。 * iii、当 s ∈ (oneMaxMove,oneMinMove+oneMaxMove) 时,先手可以导致后手无法取金币而获胜 * ans = k * 2 + 1. 其中 +1 是因为先手最后比后手多取一次。 * * @author TinyDolphin * */public class Main { public static void main(String[] args) { Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in))); PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out))); int coinsSum; // 金币的总个数 int rounds; // 回合数 int oneMinMove; // 一次取的最小数量 int oneMaxMove; // 一次取的最多数量 int ans; // 记录每回合两人一共取的次数 while (in.hasNext()) { coinsSum = in.nextInt(); rounds = in.nextInt(); for (int count = 0; count < rounds; count++) { oneMinMove = in.nextInt(); oneMaxMove = in.nextInt(); if (coinsSum % (oneMinMove + oneMaxMove) < oneMinMove) { ans = coinsSum / (oneMinMove + oneMaxMove) * 2; } else { ans = coinsSum / (oneMinMove + oneMaxMove) * 2 + 1; } out.print(ans); // 输入格式控制,最后一位换行。 out.print(count == rounds - 1 ? "\n" : " "); } } out.flush(); }}
阅读全文
0 0
- codeforces gym 100694 M The Fifth Season 巴什博弈扩展 Java
- GYM 100694 M.The Fifth Season(博弈论)
- CodeForces Gym Trainings Season 3 Episode 5 A题
- Codeforces Gym 100379I Move the queen to the corner! 威佐夫博弈变形 + 高精度
- Codeforces 12E Start of the season
- Codeforces Gym 100548H The Problem to Make You Happy (图上博弈DP)
- Codeforces Gym 100814J Game 简单博弈
- Java 2: The Complete Reference, Fifth Edition
- [Codeforces Gym] 100162A Box Game 博弈+二分图匹配
- codeforces GYM 101431E (状态压缩dp+博弈)
- CodeForces Gym 100646G The Worm Turns
- The Fifth Freedom
- The fifth day
- The fifth(static实例)
- Gym 101246DFire in the Country (dfs暴力博弈)
- Codeforces Gym 100971M Decomposition into Good Strings DP+数据结构
- Season in the sun
- codeforces 787A The Monster 扩展欧几里德 Java
- 怎么用SEO手段提高新闻点击
- Java Language Keywords(java中的关键字)
- Java异常
- Codeforces 734E Anton and Tree【并查集缩点||DFS缩点+树的直径】
- C
- codeforces gym 100694 M The Fifth Season 巴什博弈扩展 Java
- Export and Import DB2 data
- PHP中快捷函数
- springboot整合mybatis
- mysql中游标的使用
- 一个灵活设置角标的方法
- MySQL数据高级查询之连接查询、联合查询、子查询
- SVN启用注释模板实现方案
- HDU 4829 Information 带权并查集 模拟