取石子游戏 BZOJ1874 博弈
Sample OutputYES 1 1 Hint 样例中共有四堆石子,石子个数分别为7、6、9、3,每人每次可以从任何一堆石子中取出1个或者2个石子,小H有 必胜策略,事实上只要从第一堆石子中取一个石子即可。
Ai≤1000
Output
Sample Input4
7
6
9
3
2
1
2
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<bitset>
#include<ctime>
#include<deque>
#include<stack>
#include<functional>
#include<sstream>
//#pragma GCC optimize(2)
//#include<cctype>
//#pragma GCC optimize("O3")
using namespace std;
#define maxn 100005
#define inf 0x3f3f3f3f
#define INF 9999999999
#define rdint(x) scanf("%d",&x)
#define rdllt(x) scanf("%lld",&x)
#define rdult(x) scanf("%lu",&x)
#define rdlf(x) scanf("%lf",&x)
#define rdstr(x) scanf("%s",x)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int U;
#define ms(x) memset((x),0,sizeof(x))
const long long int mod = 1e9 + 7;
#define Mod 1000000000
#define sq(x) (x)*(x)
#define eps 1e-3
typedef pair<int, int> pii;
#define pi acos(-1.0)
//const int N = 1005;
#define REP(i,n) for(int i=0;i<(n);i++) inline ll rd() {
ll x = 0;
char c = getchar();
bool f = false;
while (!isdigit(c)) {
if (c == '-') f = true;
c = getchar();
}
while (isdigit(c)) {
x = (x << 1) + (x << 3) + (c ^ 48);
c = getchar();
}
return f ? -x : x;
} ll gcd(ll a, ll b) {
return b == 0 ? a : gcd(b, a%b);
}
ll sqr(ll x) { return x * x; } /*ll ans;
ll exgcd(ll a, ll b, ll &x, ll &y) {
if (!b) {
x = 1; y = 0; return a;
}
ans = exgcd(b, a%b, x, y);
ll t = x; x = y; y = t - a / b * y;
return ans;
}
*/ ll qpow(ll a, ll b, ll c) {
ll ans = 1;
a = a % c;
while (b) {
if (b % 2)ans = ans * a%c;
b /= 2; a = a * a%c;
}
return ans;
} int n, m;
int a[maxn], b[maxn];
bool vis[maxn];
int sg[maxn]; void SG() {
for (int i = 1; i <= 2000; i++) {
ms(vis);
for (int j = 1; j <= m; j++) {
if (i - b[j] >= 0)vis[sg[i - b[j]]] = 1;
}
for (int j = 0; j <= 10; j++)
if (vis[j] == 0) {
sg[i] = j; break;
}
}
} int main()
{
//ios::sync_with_stdio(0);
rdint(n);
for (int i = 1; i <= n; i++)rdint(a[i]);
rdint(m);
for (int i = 1; i <= m; i++)rdint(b[i]);
SG();
int ans = 0;
for (int i = 1; i <= n; i++)ans ^= sg[a[i]];
if (ans == 0)cout << "NO" << endl;
else {
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (a[i] - b[j] >= 0) {
if ((ans ^ (sg[a[i]]) ^ (sg[a[i] - b[j]])) == 0) {
cout << "YES" << endl;
cout << i << ' ' << b[j] << endl; return 0;
}
}
}
}
}
return 0;
}
取石子游戏 BZOJ1874 博弈的更多相关文章
- HDU 2516 取石子游戏(FIB博弈)
取石子游戏 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submi ...
- 【BZOJ1413】取石子游戏(博弈,区间DP)
题意:在研究过Nim游戏及各种变种之后,Orez又发现了一种全新的取石子游戏,这个游戏是这样的: 有n堆石子,将这n堆石子摆成一排.游戏由两个人进行,两人轮流操作,每次操作者都可以从最左或最右的一堆中 ...
- hdu 2516 取石子游戏 (Fibonacci博弈)
取石子游戏 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submi ...
- [bzoj1874][BeiJing2009 WinterCamp]取石子游戏_博弈论
取石子游戏 bzoj-1874 BeiJing2009 WinterCamp 题目大意:题目链接. 注释:略. 想法: 我们通过$SG$函数的定义来更新$SG$的转移. 如果是寻求第一步的话我们只需要 ...
- HDU 2516 取石子游戏(斐波那契博弈)
取石子游戏 Time Limit: 2000/1000 MS(Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submissi ...
- 取石子游戏(hdu1527 博弈)
取石子游戏 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Subm ...
- POJ.1067 取石子游戏 (博弈论 威佐夫博弈)
POJ.1067 取石子游戏 (博弈论 威佐夫博弈) 题意分析 简单的威佐夫博弈 博弈论快速入门 代码总览 #include <cstdio> #include <cmath> ...
- HDU.2516 取石子游戏 (博弈论 斐波那契博弈)
HDU.2516 取石子游戏 (博弈论 斐波那契博弈) 题意分析 简单的斐波那契博弈 博弈论快速入门 代码总览 #include <bits/stdc++.h> #define nmax ...
- bzoj1874 [BeiJing2009 WinterCamp]取石子游戏
1874: [BeiJing2009 WinterCamp]取石子游戏 Time Limit: 5 Sec Memory Limit: 162 MBSubmit: 925 Solved: 381[ ...
随机推荐
- Ubuntu bash不记录history方法
很多都是用: unset HISTORY HISTFILE HISTSAVE HISTZONE HISTORY HISTLOG export HISTFILE=/dev/null export HIS ...
- Mybatis 内置 Java 类型别名与 typeHandlers
aliases There are many built-in type aliases for common Java types. They are all case insensitive, n ...
- c#抓取网页数据
写了一个简单的抓取网页数据的小例子,代码如下: //根据Url地址得到网页的html源码 private string GetWebContent(string Url) { string strRe ...
- tomcat跑多个项目和不同端口访问项目
最近笔者在工作中需要同时运行多个项目,且有时需要不同端口访问项目:在此过程中,笔者觉得有必要将注意事项记录一下,以备后边查阅或广大读者借鉴. 工作环境是win7,64位,IDE为eclipse,浏览器 ...
- IDEA中Git实战
工作中多人使用版本控制软件协作开发,常见的应用场景归纳如下: 假设小组中有两个人,组长小张,组员小袁 场景一:小张创建项目并提交到远程Git仓库 场景二:小袁从远程Git仓库上获取项目源码 场景三:小 ...
- Linux 2.6 中的文件锁
简介: 本文的目的是想帮助读者理清 Linux 2.6中文件锁的概念以及 Linux 2.6 都提供了何种数据结构以及关键的系统调用来实现文件锁,从而可以帮助读者更好地使用文件锁来解决多个进程读取同一 ...
- struts2学习笔记(4)接收参数
①用action属性接收 登录界面例子 在webroot下创建login.jsp和success.jsp login.jsp中加入表单: <form action="LoginActi ...
- ListView里面嵌套CheckBox
布局文件 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:andro ...
- nodejs的POST请求
http://blog.csdn.net/puncha/article/details/9015317 Nodejs 发送HTTP POST请求实例 2013-06-03 17:55 71745人阅读 ...
- php二维数组排序方法(array_multisort,usort)
一维数组排序可以使用asort.ksort等一些方法进程排序,相对来说比较简单.二维数组的排序怎么实现呢?使用array_multisort和usort可以实现 例如像下面的数组: $users = ...