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 统计学习理论是整个机器学习到框架.试想我们学习的目的是什么呢?当然是为了具备用合理的方式处理问题的能力.统计学习理论要解决的问题就是基于数据找 ...
随机推荐
- RocketMQ入门(生产者)_2
从 RocketMQ环境搭建_1 我们已经建立了MQ的Server,接下来就是简单的生产和消费的过程. 1. rocketMQ的源码中有个示例代码example ,我们从Apache官网中可以下载源 ...
- Python中函数和方法的区别
方法是一种特殊的函数属于某个类的的函数叫方法不属于某个类的函数叫函数 转自csdn https://blog.csdn.net/weixin_40380298/article/details/7825 ...
- jquery中val属性操作
- jQuery之位置坐标图形相关方法
jQuery实例方法-位置图形 位置坐标图形大小相关方法: .offset() .position() .scrollTop() ..scrollLeft() .width()..height() . ...
- vs中添加库文件WinMM.Lib
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Lib\WinMM.Lib;
- jquery cdn bootstrap静态资源库问题
使用微软静态资源库 <script src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.9.0.min.js">&l ...
- HTML基本入门完成
四. (一)丶下拉框select元素:一般可以创建单选或多选菜单.<select>与<option>一般同时使用,select代表下拉框,option代表他的每一项. 1.基本 ...
- 操作CSS样式公共方法库
项目中常用的一些方法,我们都封装到公共方法库 let utils = (function () { //=>获取元素的样式 let getCss = function (curEle, attr ...
- 解决cpplint在Python 3下没有任何输出的问题
修改cpplint.py:1. main()中注释掉 # sys.stderr = codecs.StreamReaderWriter(sys.stderr, # codecs.getreader ...
- Verilog中关于wire使用的一些小知识
1.Verilog中如果wire连接到常量,而常量没有说明他的位宽,那么将会默认为32位 如: input [:] x ; wire [:] a; assign a = + x; 上述代码在综合的时候 ...