HackerRank - powers-game-1 【博弈论】

题意

给出 * 2^1 * 2^2 * 2^3 * 2^4 * 2^5 * 2^n 这一串东西 ,然后有两个玩家,*号是可以被替换掉的东西,可以换成+ 或者 - 然后最后的式子求出来后MOD 17 如果最后的结果 == 0 则 P2 wins 否则 P1 wins

思路

因为MOD 17 根据同余定理,我们可以 在替换*号之前就MOD 比如

2^1 2^2 2^3 2^4 2^5 2^6 2^7 2^8

2 4 8 16 15 13 9 1

然后我们发现 得到的都是一堆 0 - 15 的数字

因为都是双方出的都是最优的策略

我们发现 N = 8 的时候

分别是

1 16

2 15

4 13

8 9

这四组数据的特点是 相加都是 17

玩家一先出 如果玩家一对某一个数 换号 玩家二只要对配套数换成相同符号 即可

最后发现规律 只要N % 8 == 0 就是玩家二赢

AC代码

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <cstdlib>
#include <ctype.h>
#include <numeric>
#include <sstream>
using namespace std;
typedef long long LL;
const double PI = 3.14159265358979323846264338327;
const double E = 2.718281828459;
const int MAXN = 0x3f3f3f3f;
const int MINN = 0xc0c0c0c0;
const int maxn = 1e5 + 5;
int main()
{
int t;
cin >> t;
while (t--)
{
int n;
cin >> n;
if (n % 8 ==0)
cout << "Second\n";
else
cout << "First\n";
}
}

HackerRank - powers-game-1 【博弈论】的更多相关文章

  1. 【博弈论】【SG函数】Codeforces Round #188 (Div. 1) D. Game with Powers

    将整个游戏可以划分成若干个互不相交的子游戏. 每个子游戏的sg值只与其中的数的个数有关.而这个数不会超过30. 于是可以预处理出这个sg值表. 然后从1到n枚举,对<=sqrt(n)的部分,用个 ...

  2. IT人生知识分享:博弈论的理性思维

    背景: 昨天看了<最强大脑>,由于节目比较有争议性,不知为什么,作为一名感性的人,就想试一下如果自己理性分析会是怎样的呢? 过程是这样的: 中国队(3人)VS英国队(4人). 1:李建东( ...

  3. [poj2348]Euclid's Game(博弈论+gcd)

    Euclid's Game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9033   Accepted: 3695 Des ...

  4. 日常小测:颜色 && Hackerrank Unique_colors

    题目传送门:https://www.hackerrank.com/challenges/unique-colors 感谢hzq大神找来的这道题. 考虑点分治(毕竟是路经统计),对于每一个颜色,它的贡献 ...

  5. 博弈论揭示了深度学习的未来(译自:Game Theory Reveals the Future of Deep Learning)

    Game Theory Reveals the Future of Deep Learning Carlos E. Perez Deep Learning Patterns, Methodology ...

  6. TYVJ博弈论

    一些比较水的博弈论...(为什么都没有用到那什么SG呢....) TYVJ 1140  飘飘乎居士拯救MM 题解: 歌德巴赫猜想 #include <cmath> #include < ...

  7. Codeforces 549C. The Game Of Parity[博弈论]

    C. The Game Of Parity time limit per test 1 second memory limit per test 256 megabytes input standar ...

  8. HackerRank "Square Subsequences" !!!

    Firt thought: an variation to LCS problem - but this one has many tricky detail. I learnt the soluti ...

  9. HackerRank "Minimum Penalty Path"

    It is about how to choose btw. BFS and DFS. My init thought was to DFS - TLE\MLE. And its editorial ...

随机推荐

  1. Tuning 12 manage statistics

    这个 stattistics 对解析 sql 时的优化器有很重要的作用, 优化器是基于 statistics 来进行优化的. desc dbms_stats 包也可以 desc (早期使用 analy ...

  2. WCF系列 Restful WCF

    由于项目需要,需要完成移动端与服务端以json格式的数据交互,所以研究了Restful WCF相关内容,以实现ios端,android端与浏览器端能够与后台服务交互. 那么首先我们来了解下什么是Res ...

  3. 请写出一个超链接,点击链接后可以向zhangsan@d-heaven.com发送电子邮件。

    请写出一个超链接,点击链接后可以向zhangsan@d-heaven.com发送电子邮件. <a href=”mailto: zhangsan@d-heaven.com”>发邮件</ ...

  4. easy ui 验证框的使用

    Easy ui 插件之validatebox missingMessage:未填写时显示的信息validType:验证类型见下示例invalidMessage:无效的数据类型时显示的信息require ...

  5. improve deep learning network 课程笔记

    公开课笔记 Bias & variance bias: 1. more epoch 2. deeper network 3.hyperparameters variance : larger ...

  6. hdu 4322(最大费用最大流)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4322 思路:建图真的是太巧妙了!直接copy大牛的了: 由于只要得到糖就肯定有1个快乐度,在这一点上糖 ...

  7. hdu 4050(概率dp)

    算是挺简单的一道概率dp了,如果做了前面的聪聪于可可的话,这题不需要什么预处理,直接概率dp就行了... #include <stdio.h> #include <stdlib.h& ...

  8. Codeforces 678E(Another Sith Tournament)

    题目链接:传送门 题目大意:有n个人决斗(n<=18),每两个人之间都有一定几率杀死对方,一次进行一次决斗,胜利者成为擂主继续接受决斗直到只剩下一个人,你是一号,问你最大有多大几率存活到最后. ...

  9. iOS 修改textholder的颜色

    UITextField *textField = [[UITextField alloc]initWithFrame:CGRectMake(, , , )]; textField.placeholde ...

  10. vmware key

    VMware vRealize Suite 2017 Enterprise   N04CL-09H9H-J89DJ-0KCH6-90N0J VMware vRealize Operations Man ...