uva11859 Division Game
来源:互联网 发布:行业精英知乎 编辑:程序博客网 时间:2024/05/18 03:04
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 a row. If the row
contains all 1s, the player looses. Otherwise, the player can select
any number of integers (but at least 1 and each of them should be
greater than 1) from that row and then divides each of the selected
integers with any divisor other than 1. For example, 6 can be divided
by 2, 3 and 6, but cannot be divided by 1, 4 and 5. The player who
rst makes the matrix all 1s wins. In other words, if in his/her move,
player gets the matrix with all 1s, then he/she looses. Given the
matrix, your task is to determine whether the rst player wins or not.
Assume that both of the players will play perfectly to win. Input The
rst line has a positive integer T , T 50, denoting the number of
test cases. This is followed by each test case per line. Each test
case starts with a line containing 2 integers N and M representing the
number of rows and columns respectively. Both N and M are between 1
and 50 inclusive. Each of the next N line each contains M integers.
All these integers are between 2 and 10000 inclusive. Output For each
test case, the output contains a line in the formatCase # x : M ',
YES ’ when the
where x is the case number (starting from 1) and M is
rst player has a winning strategy and ` NO ’ otherwise.
把一个数变成他的因数相当于拿掉若干个他的质因子,把每行的质因子总数看成一堆火柴,就相当于NIM问题。
#include<cstdio>#include<cstring>#include<algorithm>using namespace std;const int maxx=10000;int f[10010],n,m;int main(){ int T,now,ans,i,j,x,K; for (i=2;i<=maxx;i++) { x=i; for (j=2;x>1;j++) while (x%j==0) { x/=j; f[i]++; } } scanf("%d",&T); for (K=1;K<=T;K++) { scanf("%d%d",&n,&m); ans=0; while (n--) { now=0; for (i=1;i<=m;i++) { scanf("%d",&x); now+=f[x]; } ans^=now; } printf("Case #%d: %s\n",K,ans?"YES":"NO"); }}
- uva11859 Division Game
- UVA11859
- UVA 11859 - Division Game
- UVA - 11859 Division Game
- HDU 6036 Division Game
- uva 11859 - Division Game(Nim)
- UVA 11859 - Division Game (SG博弈)
- UVA 11859 - Division Game(Nim游戏)
- UVA 11859 Division Game (Nim博弈)
- Division
- Division
- Division
- Division
- Division
- HDU 6036 Division Game(组合数学+NTT)
- Division Operation
- pku_3140_Contestants Division
- Set Division
- LNMP环境搭建!!!
- ~/.bashrc 配置
- 程序设计实训项目二 歌手大奖赛计分程序
- H5+APP开发,iOS下拉弹回特效实现CSS
- jQuery对象方法操作html元素内容
- uva11859 Division Game
- Java代码覆盖率工具(Sonar+Jacoco)部署
- 利用git工具上传本地代码到远程仓库
- Linux Awk命令详解
- c语言函数指针的理解与使用
- 【leetcode】1.Two Sum
- ie下兼容奇偶
- DirectVobSub(VsFilter)的基本原理和实现实现
- Oracle分页