UVa 11859 (Nim) Division Game

把每一行m个数所有的素因子看做一堆,就把问题转化为n堆的Nim游戏。

然后预处理一下10000以内每个数素因数的个数,再根据书上的Bouton定理,计算一下n行素因数个数的异或和。

为0是先手必败局面,输出NO,否则输出YES

 1 #include <cstdio>
 2 #include <cmath>
 3
 4 const int maxp = 10000;
 5 int f[maxp + 10];
 6
 7 int main()
 8 {
 9     //freopen("in.txt", "r", stdin);
10
11     for(int i = 2; i <= maxp; i++) if(!f[i])
12     {
13         int t = i;
14         while(t <= maxp)
15         {
16             for(int j = t; j <= maxp; j += t) f[j]++;
17             t *= i;
18         }
19     }
20
21     int T;
22     scanf("%d", &T);
23     for(int kase = 1; kase <= T; ++kase)
24     {
25         int n, m;
26         scanf("%d%d", &n, &m);
27         int xorsum = 0;
28         for(int i = 0; i < n; i++)
29         {
30             int cnt = 0;
31             for(int j = 0; j < m; j++)
32             {
33                 int x;
34                 scanf("%d", &x);
35                 cnt += f[x];
36             }
37             xorsum ^= cnt;
38         }
39         printf("Case #%d: %s\n", kase, xorsum ? "YES" : "NO");
40     }
41
42     return 0;
43 }

代码君

时间: 2024-08-10 20:11:02

UVa 11859 (Nim) Division Game的相关文章

UVA - 11859 Division Game

Division game is a 2-player game.In this game, there is a matrix of positive integers with N rows and M columns.Players make their moves in turns. In each step, the current player selects arow. If the row contains all 1s, the player looses. Otherwise

UVA 1559 - Nim(博弈dp)

UVA 1559 - Nim 题目链接 题意:一开始有s个石子,2n个人轮流取石子,每个人有个最大能取数目,2n个人奇数一队,偶数一队,取到最后一个石子的队输,问谁赢 思路:记忆化搜索,每个人取的时候对应的后继状态如果有一个必败态,则该状态为必胜态,如果都是必胜态,则该状态为必败态 代码: #include <stdio.h> #include <string.h> int n, s, m[25], dp[25][10005]; int dfs(int now, int state

uva 1559 - Nim(记忆化+博弈)

题目链接:uva 1559 - Nim 题目大意:有n个人,奇数的为一队,偶数的为一对,两队分别从一堆石子个数为S的石子堆中取石子,取到最后一个石子一方则视为失败.给出各个队员每次可取石子的上限值,然后按照顺序操作. 解题思路:dp[i][s]表示第i个选手操作时剩s个石子时为必胜还是必败.因为是取到最后一个石子的为输,所以最后递归结束的条件和不同的略有不同. 还尝试过可以将石子数减1,然后普通处理也是可以. /******************* * 取到最后一个石子的输 * *******

UVA 11859 Division Game (Nim博弈)

题目:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=32746 题意:有一个n*m(1<=n,m<=50)矩阵,每个元素均为2~10000之间的正整数,两个游戏者轮流操作.每次可以选一行中的1个或者大于1的整数,把他们中的每个数都变成它的某个真因子,比如12可以边长1,2,3,4或者6,不能操作的输. 分析:考虑每个数包含的素因子个数(比如12=2*2*3包含3个素因子),则让一个数"变成它的素因子"

UVA 11859 Division Game[Nim游戏]

题意:给定一个N*M的矩阵,每次可以选择同一行中的若干个数,把它们变成它们的质因子.问说先手的可否获胜. 同一行相当于1堆,数量就是所有数的质因子个数之和 #include <iostream> #include <cstdio> #include <algorithm> #include <cstring> #include <cmath> using namespace std; const int N=55; inline int read

UVa 10407 - Simple division

题目:给你几个数,求使他们同于的最大除数. 分析:数论.取其中两不相同数的差,差值一定是除数的倍数,利用差值枚举除数即可. 说明:小心都是素数的情况,被坑了╮(╯▽╰)╭. #include <algorithm> #include <iostream> #include <cstdlib> #include <cstdio> #include <cmath> using namespace std; long long save[1001];

组合游戏简单题

UVA - 11859 - Division Game 题目传送:Division Game AC代码: #include <map> #include <set> #include <list> #include <cmath> #include <deque> #include <queue> #include <stack> #include <bitset> #include <cctype>

uva 1566 - John(Nim)

题目链接:uva 1566 - John 题目大意:反Nim游戏,除了取到最后一个石子的为输,其他规则和Nim游戏相同. 解题思路:特判全为1的情况,负责答案就是Nim和. #include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int maxn = 50; int main () { int cas; scanf("%d", &

UVa 725 Division --- 简单枚举

题目链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=666 /* UVa 725 Division --- 简单枚举 */ #include <cstdio> #include <cstring> bool used[10]; /* 判断传进来的两个数是否满足条件 */ bool judge(int a, i