取石子游戏 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[ ...
随机推荐
- FFMPEG: avformat_find_stream_info()函数
av_find_stream_info()中是要不断的读取数据包,解码获得相应的信息 其中: st->codec->codec_type:0:视频,1:音频,2:数据 st->cod ...
- Android webRTC 代码下载编译
1.安装depot tools git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git 然后把把depot ...
- ubuntu系统里vi编辑器时,按方向箭头输入是乱码的ABCD字母?(图文详解)
不多说,直接上干货! 问题详情 ubuntu系统里vi编辑器时,按方向箭头输入是乱码的ABCD字母? 解决办法 是由于预装的vim软件没更新,运行 sudo apt-get install vi ...
- zookeeper 安装配置注意事项
zoo.cfg 1.server.1/2/3 有几台配置几个 2.配置好hosts映射之后可以用node1替代IP地址 3.dataLogDir 下面配置的logs 的目录一定要创建 4.dat ...
- 使用php输出时间格式
<? date_default_timezone_set("ETC/GMT-8"); $tm=time(); echo date("Y-m-d h:i a" ...
- 将字符串str1复制为字符串str2的三种方法
1.自己编写函数,将两个字符串进行复制 #include<iostream> using namespace std; int main(){ char str1[]="I lo ...
- SpringBoot06 统一响应格式
1 要求 每个请求成功后,后台返回的响应格式都是一致的,例如: 2 创建一个视图模型 该模型用于格式化响应数据 package cn.xiangxu.springboottest.model.data ...
- MSScriptControl详解(可实现在C#等语言中调用JAVASCRIPT代码)
ScriptControl接口 属性名称 类型 备注 AllowUI BOOL 检测是否允许运行用户的接口元素.如果为False,则诸如消息框之类的界面元素不可见. CodeObject Object ...
- Python沙盒环境配置
一.简介 本文介绍配置python沙盒环境的方法步骤. 二.安装步骤 1.安装pyenv http://www.cnblogs.com/274914765qq/p/4948530.html 2.安装v ...
- Django框架 之 URLconf
Django框架 之 URLconf 浏览目录 URL 摘要 Django如何处理一个请求 反向解析URL name模式 namespace模式 一.URL 1.摘要 我们要在Django项目中为应用 ...