Game Theory
HDU 5795 || 3032
把x个石子的堆分成非空两(i, j)或三堆(i, j, k)的操作->(sg[i] ^ sg[j])或(sg[i] ^ sg[j] ^ sg[k])是x的后继
#define pron "hdu5795"
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std; const int maxn = ; int sg[maxn + ];
bool vis[maxn + ]; int mex(){
for (int i = ; i <= maxn; i ++)
if (not vis[i])
return i;
} int get_sg(int x){
if (sg[x] != -)
return sg[x]; memset(vis, false, sizeof vis); for (int i = ; i < x; i ++){
int temp = get_sg(i);
vis[temp] = true; for (int j = ; j < x - i; j ++)
vis[temp ^ get_sg(j) ^ get_sg(x - i - j)] = true;
} return sg[x] = mex();
} int get_sg(int x){
if (x % == )
return x - ;
if (x % == )
return x + ;
return x;
} int main(){
#ifndef online_judge
freopen(pron ".in", "r", stdin);
#endif
int tcase, n, flag, temp; scanf("%d", &tcase);
while (tcase --){
flag = ; scanf("%d", &n);
for (int i = ; i < n; i ++){
scanf("%d", &temp);
flag ^= get_sg(temp);
} if (flag)
puts("first player wins.");
else
puts("second player wins.");
}
}
5795
#define PRON "hdu3032"
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std; const int MAXN = ; bool vis[MAXN + ];
int sg[MAXN + ]; int mex(){
for (int i = ; i <= MAXN; i ++)
if (not vis[i])
return i;
} int get_sg(int x){
if (sg[x] != -)
return sg[x]; memset(vis, false, sizeof vis); int temp;
for (int i = ; i < x; i ++){
temp = get_sg(i);
vis[temp] = vis[temp ^ get_sg(x - i)] = true;
} return sg[x] = mex();
} int get_SG(int x){
if (x % == )
return x - ;
if (x % == )
return x + ;
return x;
} int main(){
#ifndef ONLINE_JUDGE
freopen(PRON ".in", "r", stdin);
#endif
memset(sg, -, sizeof sg); int Tcase, n, temp, flag; scanf("%d", &Tcase);
while (Tcase --){
flag = ; scanf("%d", &n);
while (n --){
scanf("%d", &temp);
flag ^= get_SG(temp);
} if (flag)
puts("Alice");
else
puts("Bob");
}
}
3032
HDU 1536 || 1944
直接get_sg,不需要打表找规律
#define PRON "hdu1536"
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std; const int MAXK = + ;
const int MAXN = ; bool vis[MAXN + ];
int k, Tcase, n, h, flag, s[MAXK], sg[MAXN + ]; int mex(){
for (int i = ; i <= MAXN; i ++)
if (not vis[i])
return i;
} void get_sg(){
memset(sg, , sizeof sg); for (int i = , j; i <= MAXN; i ++){
memset(vis, false, sizeof vis); j = ;
while (i >= s[j] && j < k)
vis[sg[i - s[j ++]]] = true; sg[i] = mex();
}
} int main(){
#ifndef ONLINE_JUDGE
freopen(PRON ".in", "r", stdin);
#endif while (scanf("%d", &k) == && k){
for (int i = ; i < k; i ++)
scanf("%d", &s[i]);
sort(s, s + k); get_sg(); scanf("%d", &Tcase);
while (Tcase --){
flag = ; scanf("%d", &n);
for (int i = ; i < n; i ++){
scanf("%d", &h);
flag ^= sg[h];
} if (flag)
putchar('W');
else
putchar('L');
} putchar();
}
}
1536
Codeforces 768E
取石子,但是对于每一堆,不能取相同的个数。比如这一堆被拿走了x个,下一次就不能再拿x个了。
官方题解用的dp。但这道题可以...
处理一个数组a[i], 表示取完i个石子最多需要的步骤数,即 1 + 2 + .... + a[i] <= i。由于是后手,所以前者采取什么策略我就可以采取什么策略,因此求一个异或和就好。
#define PRON "768e"
#include <cstdio>
#include <vector>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll; const int maxn = ; int n, a[maxn]; int main(){
#ifndef ONLINE_JUDGE
freopen(PRON ".in", "r", stdin);
#endif memset(a, , sizeof a);
for (int i = , j = ; i <= ; i ++){
while (j * (j + ) / <= i)
++ j; a[i] = -- j;
} scanf("%d", &n);
int flag = , p;
while (n --){
scanf("%d", &p);
flag ^= a[p];
} puts(flag ? "NO" : "YES");
}
768E
Game Theory的更多相关文章
- Introduction to graph theory 图论/脑网络基础
Source: Connected Brain Figure above: Bullmore E, Sporns O. Complex brain networks: graph theoretica ...
- 博弈论揭示了深度学习的未来(译自:Game Theory Reveals the Future of Deep Learning)
Game Theory Reveals the Future of Deep Learning Carlos E. Perez Deep Learning Patterns, Methodology ...
- Understanding theory (1)
Source: verysmartbrothas.com It has been confusing since my first day as a PhD student about theory ...
- Machine Learning Algorithms Study Notes(3)--Learning Theory
Machine Learning Algorithms Study Notes 高雪松 @雪松Cedro Microsoft MVP 本系列文章是Andrew Ng 在斯坦福的机器学习课程 CS 22 ...
- Java theory and practice
This content is part of the series: Java theory and practice A brief history of garbage collection A ...
- CCJ PRML Study Note - Chapter 1.6 : Information Theory
Chapter 1.6 : Information Theory Chapter 1.6 : Information Theory Christopher M. Bishop, PRML, C ...
- 信息熵 Information Theory
信息论(Information Theory)是概率论与数理统计的一个分枝.用于信息处理.信息熵.通信系统.数据传输.率失真理论.密码学.信噪比.数据压缩和相关课题.本文主要罗列一些基于熵的概念及其意 ...
- Computer Science Theory for the Information Age-4: 一些机器学习算法的简介
一些机器学习算法的简介 本节开始,介绍<Computer Science Theory for the Information Age>一书中第六章(这里先暂时跳过第三章),主要涉及学习以 ...
- Computer Science Theory for the Information Age-1: 高维空间中的球体
高维空间中的球体 注:此系列随笔是我在阅读图灵奖获得者John Hopcroft的最新书籍<Computer Science Theory for the Information Age> ...
- Learning Theory
Empiricial Risk Minimization 统计学习理论是整个机器学习到框架.试想我们学习的目的是什么呢?当然是为了具备用合理的方式处理问题的能力.统计学习理论要解决的问题就是基于数据找 ...
随机推荐
- Matplotlib-多图合并显示
Subplot 多合一显示 均匀图中图 不均匀图中图 # 均匀图中图 # matplotlib 是可以组合许多的小图, 放在一张大图里面显示的. 使用到的方法叫作 subplot. # 使用impor ...
- java过滤emoji表情
import java.util.regex.Matcher; import java.util.regex.Pattern; public class test { /** * 表情过滤 * */ ...
- 关于Qrc文件的用法
在python文件xxx.py中调用资源文件,一般来说,需要将资源放在xxx.py的相同目录下:然而,当在xxx.py下建立一个统一目录/rec则需要建立xxx.qrc文件才能让xxx.py调用,调用 ...
- EasyUI在window中使用kindeditor 4.1.10在IE9中不能回显、获得焦点编辑的问题
描述 :kindeditor4.1.10版本是当前最新的版本,在浏览器兼容性和功能方面都是值得一赞的,在开发中能方便快捷的满足一些开发需求. 问题 : 问题总是有的. 在使用过程中,遇到EasyU ...
- H5-处理支付-前端部分
调用后台支付接口,得到返回数据 1.如果是支付宝,需要后台配置支付成功的回调页面路径,还要在页面创建一个标签装表单内容,此处是id为box的div标签 <div id="box&quo ...
- JUnit源码分析 - 扩展 - 自定义Rule
JUnit Rule简述 Rule是JUnit 4.7之后新加入的特性,有点类似于拦截器,可以在测试类或测试方法执行前后添加额外的处理,本质上是对@BeforeClass, @AfterClass, ...
- CentOS7编译安装mysql-5.6.43
Step 1:安装编译需要的软件和工具 [root@node-1 ~]# yum install gcc gcc-c++ cmake ncurses-devel bison Step 2:创建mysq ...
- [SSM项目]Eclipse 搭建marven-web项目 hello world!
配置的种种 (仅第一次)eclipse配置好tomcat.jdk.marven: 建立项目:建立mvn project-选择mvn-web 消除警告和错误: 解决错误1-项目propriety-Jav ...
- audiounit错误码对应值查询
https://www.osstatus.com/search/results?platform=all&framework=all&search=(错误码的值) EX: https ...
- 关于easyui框架中a标签使用onclick()触发事件偶尔会选项卡消失BUG解决方案
今天发现公司的一个easyui项目中有个页面会在触发onclick事件时选项卡消失,如下图 产生BUG后 产生BUG前 查找很多地方还有资料不知道哪里出现的问题,看了下框架源码之类的,因为不是专门的前 ...