HDU 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
HDU Game Theory的更多相关文章
- HDU 6343.Problem L. Graph Theory Homework-数学 (2018 Multi-University Training Contest 4 1012)
6343.Problem L. Graph Theory Homework 官方题解: 一篇写的很好的博客: HDU 6343 - Problem L. Graph Theory Homework - ...
- HDU 2685 I won't tell you this is about number theory
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2685 题意:求gcd(a^m - 1, a^n - 1) mod k 思路:gcd(a^m - 1, ...
- HDU 6343 - Problem L. Graph Theory Homework - [(伪装成图论题的)简单数学题]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6343 Time Limit: 2000/1000 MS (Java/Others) Memory Li ...
- hdu分类 Math Theory(还有三题!)
这个分类怎么觉得这么水呢.. 这个分类做到尾的模板集: //gcd int gcd(int a,int b){return b? gcd(b, a % b) : a;} //埃氏筛法 O(nlogn) ...
- hdu 2685 I won't tell you this is about number theory 数论
题目链接 根据公式 \[ gcd(a^m-1, a^n-1) = a^{gcd(m, n)}-1 \] 就可以很容易的做出来了. #include <iostream> #include ...
- HDU 6029 Graph Theory
贪心. 每次找到后面最近的一个能连边的连边. #include <bits/stdc++.h> using namespace std; ; int T,n,k; ],b[],u[]; i ...
- hdu 6661 Acesrc and String Theory (后缀数组)
大意: 求重复$k$次的子串个数 枚举重复长度$i$, 把整个串分为$n/i$块, 如果每块可以$O(1)$计算, 那么最终复杂度就为$O(nlogn)$ 有个结论是: 以$j$开头的子串重复次数最大 ...
- HDU 3341 Lost's revenge(AC自动机+DP)
Lost's revenge Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)T ...
- HDU 3336 Count the string(KMP的Next数组应用+DP)
Count the string Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
随机推荐
- python基础知识7——迭代器,生成器,装饰器
迭代器 1.迭代器 迭代器是访问集合元素的一种方式.迭代器对象从集合的第一个元素开始访问,直到所有的元素被访问完结束.迭代器只能往前不会后退,不过这也没什么,因为人们很少在迭代途中往后退.另外,迭代器 ...
- SQL日期格式,转自will哥
我之前一直認為 SQL Server 針對日期處理的函數不夠多(如果跟 MySQL 比較),尤其是處理日期欄位轉字串的時候,常常因為要輸出特定的格式而懊惱不已,常常一不小心就寫了一長串,很不易閱讀. ...
- Servlet学习五——流的分发
在上一节中有提到,流的传输,可以考虑Stream,但如果需要同时分发流和其它信息,,就需要再考虑其它方式了. 在coding中,服务端查询结果都是以gson进行传输,当需要传输一个语音并且同时需要传输 ...
- python-基础介绍
一.Linux基础 - 计算机以及日后我们开发的程序防止的服务器的简单操作 二.Python开发 http://www.cnblogs.com/wupeiqi/articles/5433893.htm ...
- 【NoSql】MongoDb
[NoSql]MongoDb 一. 文档 1. 官网 2. C# Driver 3. C# 开发文档 二. 命令 1. --config "C:\mongodb\mongod.cfg&quo ...
- Java abstract class 和 interface 的区别
Java abstract class 和 interface 的区别 1. abstract class和interface是Java语言中对于抽象类定义进行支持的两种机制 2. 以Door的抽象概 ...
- Matrix Calculator
表达式分析+矩阵+计算器+寄存器=矩阵计算器 怎么想起来搞这个呢.. //刚看龙书兴致勃勃要搞表达式分析 这个寄存器比较简陋,26字母+4缓存,//字母不分大小写 当然,不只能算矩阵,还能算数= = ...
- mac--又发现了一款mac快捷键神器
之前用applescript,还有keyboard maestro,前段时间用机械键盘的时候,用开源的karabiner重新设置机械键盘的键位. 今天因为网上抄的键位F4想换成Launchpad,所以 ...
- The path to the driver executable must be set by the webdriver.gecko.driver system property
报这个错,是因为你使用了selenium3+Firefox.在selenium3中,使用Firefox,需要添加驱动. 您可以从Github上下载驱动程序下载网址- https://github.c ...
- 关于JS获取来路url问题
Javascript 正常取来源网页的URL只要用: document.referrer 就可以了! 但,如果来源页是Javascript跳转过来的,上边的方法就拿不到了!所以用: opene ...