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

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

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

 #include <cstdio>
#include <cmath> const int maxp = ;
int f[maxp + ]; int main()
{
//freopen("in.txt", "r", stdin); for(int i = ; i <= maxp; i++) if(!f[i])
{
int t = i;
while(t <= maxp)
{
for(int j = t; j <= maxp; j += t) f[j]++;
t *= i;
}
} int T;
scanf("%d", &T);
for(int kase = ; kase <= T; ++kase)
{
int n, m;
scanf("%d%d", &n, &m);
int xorsum = ;
for(int i = ; i < n; i++)
{
int cnt = ;
for(int j = ; j < m; j++)
{
int x;
scanf("%d", &x);
cnt += f[x];
}
xorsum ^= cnt;
}
printf("Case #%d: %s\n", kase, xorsum ? "YES" : "NO");
} return ;
}

代码君

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

  1. Division Game UVA - 11859 Nim

    Code: #include<cstdio> #include<algorithm> using namespace std; #define maxn 10005 int n ...

  2. UVA 11859 Division Game[Nim游戏]

    题意:给定一个N*M的矩阵,每次可以选择同一行中的若干个数,把它们变成它们的质因子.问说先手的可否获胜. 同一行相当于1堆,数量就是所有数的质因子个数之和 #include <iostream& ...

  3. UVA 11859 - Division Game

    看题传送门 题目大意 有一个n * m的矩阵,每个元素均为2~10000之间的正整数,两个游戏者轮流操作.每次可选一行中的1个或者多个大于1的整数把它们中的每个数都变成它的某个真因子,比如12可以变成 ...

  4. 【例题 7-1 UVA - 725】Division

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 枚举分母从0到99999. 得到分子,判断合法 [代码] /* 1.Shoud it use long long ? 2.Have ...

  5. 暴力枚举 UVA 725 Division

    题目传送门 /* 暴力:对于每一个数都判断,是否数字全都使用过一遍 */ #include <cstdio> #include <iostream> #include < ...

  6. uva 725 Division(暴力模拟)

    Division 紫书入门级别的暴力,可我还是写了好长时间 = = [题目链接]uva 725 [题目类型]化简暴力 &题解: 首先要看懂题意,他的意思也就是0~9都只出现一遍,在这2个5位数 ...

  7. uva 725 Division(除法)暴力法!

    uva 725  Division(除法) A - 暴力求解 Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & ...

  8. UVA.725 Division (暴力)

    UVA.725 Division (暴力) 题意分析 找出abcdefghij分别是0-9(不得有重复),使得式子abcde/fghij = n. 如果分别枚举每个数字,就会有10^10,肯定爆炸,由 ...

  9. 除法(Division ,UVA 725)-ACM集训

    参考:http://www.cnblogs.com/xiaobaibuhei/p/3301110.html 算法学到很弱,连这么简单个问题都难到我了.但我偏不信这个邪,终于做出来了.不过,是参照别人的 ...

随机推荐

  1. 8种方法提升windows 8使用方便-----Win+x 编辑菜单

    在windows 8上,你可以同时按下windows键和x键或者右键点击屏幕左下角打开一个菜单名为电源菜单或者快速访问菜单,这个菜单包含快速访问系统的工具,如控制面板,命令提示符,任务管理器,资源管理 ...

  2. Android ADB 端口占用问题解决方案

    问题描述: The connection to adb is down, and a severe error has occured. You must restart adb and Eclips ...

  3. ajax正确返回数据,却进入了error分支

    .net 开发: $.ajax({ type: "POST", //post没有数据量限制 url: "ashx/PostHandle.ashx", data: ...

  4. Reference in the manifest does not match the identity of the downloaded assembly

    solution 1 :http://stackoverflow.com/questions/5337458/error-deploying-clickonce-application-referen ...

  5. PHP 中的BOM BUG

    对于PHP,一个小小让我不敢置信的事情很多,包括引用变量哪么迟钝,普通变量哪么牛B我己经很意外,甚至现在竟然出现了BOM头的BUG. 在PHP中,会引用很多小文件,include或require,哪么 ...

  6. c++ std::bitset

    转载自 作用:及  64位 移位  取或  用64个位存储64个位,取 或 merge . 然后查索引即知道id是否存在~~ 目标:省空间. #include <iostream> #in ...

  7. 【HDOJ】【3037】Saving Beans

    排列组合 啊……这题是要求c(n-1,0)+c(n,1)+c(n+1,2)+......+c(n+m-1,m) 这个玩意……其实就等于c(n+m,m) 好吧然后就是模P……Lucas大法好= = 我S ...

  8. error X3025:global variables are implicitly constant, enable compatibility mode to allow modification

    global variables are implicitly constant, enable compatibility mode to allow modification http://xbo ...

  9. spring mvc 数据绑定总结

    spring mvc 做web开发时,经常会不知道如何合适绑定页面数据.用惯struts2的朋友更认为spring mvc 绑定数据不如struts2方便(本人最开始也是这么认为),经过一段时间的应用 ...

  10. jstl表达式使用方法

    1.jstl.jar  servlet.jar支持 2.jsp引入标签库 <%@ taglib prefix="c" uri="http://java.sun.co ...