# bzoj1874 [BeiJing2009 WinterCamp]取石子游戏

## 1874: [BeiJing2009 WinterCamp]取石子游戏

Time Limit: 5 Sec  Memory Limit: 162 MB
Submit: 925  Solved: 381
[Submit][Status][Discuss]

，第一步如何取石子。

N≤10 Ai≤1000

4
7
6
9
3
2
1
2

YES
1 1
Hint

## Source

Day2

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

const int maxn = 1010;
int n,a[maxn],sg[maxn],ans,Tim,vis[maxn],b[maxn],m;

void init()
{
for (int i = 1; i <= 1000; i++)
{
Tim++;
for (int j = 1; j <= m; j++)
{
if (i - b[j] >= 0)
vis[sg[i - b[j]]] = Tim;
}
for (int j = 0; j <= 10; j++)
if (vis[j] != Tim)
{
sg[i] = j;
break;
}
}
}

int main()
{
scanf("%d",&n);
for (int i = 1; i <= n; i++)
scanf("%d",&a[i]);
scanf("%d",&m);
for (int i = 1; i <= m; i++)
scanf("%d",&b[i]);
init();
for (int i = 1; i <= n; i++)
{
if (i == 1)
ans = sg[a[i]];
else
ans ^= sg[a[i]];
}
if (ans == 0)
puts("NO");
else
{
puts("YES");
for (int i = 1; i <= n; i++)
{
bool flag = false;
for (int j = 1; j <= m; j++)
{
if (a[i] >= b[j] && (ans ^ sg[a[i]] ^ sg[a[i] - b[j]]) == 0)
{
printf("%d %d\n",i,b[j]);
flag = 1;
break;
}
}
if (flag)
break;
}
}

return 0;
}

posted @ 2018-04-04 15:54  zbtrs  阅读(269)  评论(0编辑  收藏  举报