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 统计学习理论是整个机器学习到框架.试想我们学习的目的是什么呢?当然是为了具备用合理的方式处理问题的能力.统计学习理论要解决的问题就是基于数据找 ...
随机推荐
- mysql 函数获取子节点
DELIMITER $$ USE `topsale`$$ DROP FUNCTION IF EXISTS `getShopIdByUserId`$$ CREATE DEFINER=`root`@`%` ...
- Redis系列十:缓存雪崩、缓存穿透、缓存预热、缓存更新、缓存降级
一.缓存雪崩 缓存雪崩我们可以简单的理解为:由于原有缓存失效,新缓存未到期间(例如:我们设置缓存时采用了相同的过期时间,在同一时刻出现大面积的缓存过期),所有原本应该访问缓存的请求都去查询数据库了,而 ...
- Game Engine Architecture 3
[Game Engine Architecture 3] 1.Computing performance—typically measured in millions of instructions ...
- superset在 centos 7安装运行
参考:1.http://blog.csdn.net/u014729236/article/details/76302888?locationNum=2&fps=1 2.https://www. ...
- Node.js的内存问题
v8堆内存限制默认是1GB,所以可能成为瓶颈. 但是Buffer的内存不受限制,而且可以开多个Nodejs实例然后通过代理进行负载均衡,不过不知道这样效果怎么样呢? 但是基本上应该内存的话不会成为单实 ...
- 获取select下拉框选中的的值
有一id=test的下拉框,怎么获取选中的那个值呢? 分别使用javascript方法和jquery方法 <select id="test" name="&quo ...
- Json常用代码
以下使用的都是fastJson. 先创建Person类,如下: public class Person { @JSONField(name = "AGE") private int ...
- 再次认识void
重新认识void 在初学c/c++时感觉void是一个很不起眼的关键字.因为在c++中我使用的还是比较少的.但是到了Linux中,不论是在内核源码中还是在程序编写的过程中有关void与*的组合随处可见 ...
- Analysis Services(SSAS) 性能优化
1.聚合选项中添加聚合,以空间换时间提升性能. 如下图: 性能提升百分比越高,聚合数越高,生成的Cube越大,这就是以空间换时间. 2.修改SSAS服务器上的线程池配置选项.提升并发数. 通过X:\P ...
- vue的表单输入绑定
1.单行绑定 <p>{{logintype}}</p> <input type="text" v-model="logintype" ...