HDUOJ-----取(m堆)石子游戏

时间:2022-05-05
本文章向大家介绍HDUOJ-----取(m堆)石子游戏,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

取(m堆)石子游戏

Time Limit : 3000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 2   Accepted Submission(s) : 2

Problem Description

m堆石子,两人轮流取.只能在1堆中取.取完者胜.先取者负输出No.先取者胜输出Yes,然后输出怎样取子.例如5堆 5,7,8,9,10先取者胜,先取者第1次取时可以从有8个的那一堆取走7个剩下1个,也可以从有9个的中那一堆取走9个剩下0个,也可以从有10个的中那一堆取走7个剩下3个.

Input

输入有多组.每组第1行是m,m<=200000. 后面m个非零正整数.m=0退出.

Output

先取者负输出No.先取者胜输出Yes,然后输出先取者第1次取子的所有方法.如果从有a个石子的堆中取若干个后剩下b个后会胜就输出a b.参看Sample Output.

Sample Input

2

45 45

3

3 6 9

5

5 7 8 9 10 0

Sample Output

No

Yes

9 5

Yes

8 1

9 0

10 3

Author

Zhousc

尼姆博弈:

代码:

 1 #include<iostream>
 2 #include<vector>
 3 #include<cstdio>
 4 using namespace std;
 5 int main()
 6 {
 7     int n,m,i,x;
 8     vector<int>arr;
 9     while(scanf("%d",&n),n)
10     {
11          arr.clear();
12        for(x=i=0; i<n; i++)
13        {
14            scanf("%d",&m);
15            x^=m;
16            arr.push_back(m);
17        }
18        if(x)
19        {
20           printf("Yesn");
21          for(i=0;i<n;i++)
22          {
23              int temp=x^arr[i];
24           if(temp<arr[i])
25               printf("%d %dn",arr[i],temp);
26          }
27        }
28        else
29            printf("NOn");
30     }
31     return 0;
32 }