HDU5088(高斯消元)

Revenge of Nim II

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 443    Accepted Submission(s): 157

Problem Description

Nim is a mathematical game of strategy in which two players take turns removing objects from distinct heaps. On each turn, a player must remove at least one object, and may remove any number of objects provided they all come from the same heap.

---Wikipedia

Today, Nim takes revenge on you, again. As you know, the rule of Nim game is rather unfair, only the nim-sum (⊕) of the sizes of the heaps is zero will the first player lose. To ensure the fairness of the game, the second player has a chance to move some (can
be zero) heaps before the game starts, but he has to move one heap entirely, i.e. not partially. Of course, he can’t move all heaps out, at least one heap should be left for playing. Will the second player have the chance to win this time?

Input

The first line contains a single integer T, indicating the number of test cases.

Each test case begins with an integer N, indicating the number of heaps. Then N integer Ai follows, indicating the number of each heap.

[Technical Specification]

1. 1 <= T <= 100

2. 1 <= N <= 1 000

3. 1 <= Ai <= 1 000 000 000 000

Output

For each test case, output “Yes” if the second player can win by moving some (can be zero) heaps out, otherwise “No”.

Sample Input

3
1
2
3
2 2 2
5
1 2 3 4 5

Sample Output

No
Yes
Yes

Hint

For the third test case, the second player can move heaps with 4 and 5 objects out, so the nim-sum of the sizes of the left heaps is 1⊕2⊕3 = 0.

题意:RT

思路:将每个数的每一位看成列,n个数看成n行,由于数值是<=1e12的,所以最多也就40列,如果行数大于40,那么一定可以用高斯消元得到至少有两个数是相等的(一个数是0也行)

如果n<=40那么直接高斯消元求解即可

时间: 2024-08-27 18:09:46

HDU5088(高斯消元)的相关文章

HDU5088——Revenge of Nim II(高斯消元&amp;矩阵的秩)(BestCoder Round #16)

Revenge of Nim II Problem DescriptionNim is a mathematical game of strategy in which two players take turns removing objects from distinct heaps. On each turn, a player must remove at least one object, and may remove any number of objects provided th

poj_1222_高斯消元

第一次学习使用高斯消元,将灯板化为线性方程组,进行求解. /*######################################################################### # File Name: poj_1222.cpp # Author: CaoLei # Created Time: 2015/7/20 15:48:04 ###################################################################

HDU 4870 Rating(高斯消元)

HDU 4870 Rating 题目链接 题意:一个人注册两个账号,初始rating都是0,他每次拿低分的那个号去打比赛,赢了加50分,输了扣100分,胜率为p,他会打到直到一个号有1000分为止,问比赛场次的期望 思路:f(i, j)表示i >= j,第一个号i分,第二个号j分时候,达到目标的期望,那么可以列出转移为f(i, j) = p f(i', j') + (1 - p) f(i'' + j'') + 1 f(i', j')对应的是赢了加分的状态,f(i'', j'')对应输的扣分的状态

【BZOJ 4171】 4171: Rhl的游戏 (高斯消元)

4171: Rhl的游戏 Time Limit: 20 Sec  Memory Limit: 128 MBSubmit: 74  Solved: 33[Submit][Status][Discuss] Description RHL最近迷上一个小游戏:Flip it.游戏的规则很简单,在一个N*M的格子上,有一些格子是黑色,有一些是白色 .每选择一个格子按一次,格子以及周围边相邻的格子都会翻转颜色(边相邻指至少与该格子有一条公共边的格子 ),黑变白,白变黑.RHL希望把所有格子都变成白色的.不幸

POJ 1830 开关问题 高斯消元,自由变量个数

http://poj.org/problem?id=1830 如果开关s1操作一次,则会有s1(记住自己也会变).和s1连接的开关都会做一次操作. 那么设矩阵a[i][j]表示按下了开关j,开关i会被操作一次,记得a[i][i] = 1是必须的,因为开关i操作一次,本身肯定会变化一次. 所以有n个开关,就有n条方程, 每个开关的操作次数总和是:a[i][1] + a[i][2] + ... + a[i][n] 那么sum % 2就代表它的状态,需要和(en[i] - be[i] + 2) % 2

BZOJ 3105: [cqoi2013]新Nim游戏 [高斯消元XOR 线性基]

以后我也要用传送门! 题意:一些数,选择一个权值最大的异或和不为0的集合 终于有点明白线性基是什么了...等会再整理 求一个权值最大的线性无关子集 线性无关子集满足拟阵的性质,贪心选择权值最大的,用高斯消元判断是否和已选择的线性相关 每一位记录pivot[i]为i用到的行 枚举要加入的数字的每一个二进制为1的位,如果有pivot[i]那么就异或一下(消元),否则pivot[i]=这个数并退出 如果最后异或成0了就说明线性相关... #include <iostream> #include &l

[bzoj1013][JSOI2008]球形空间产生器sphere-题解[高斯消元]

Description 有一个球形空间产生器能够在n维空间中产生一个坚硬的球体.现在,你被困在了这个n维球体中,你只知道球面上n+1个点的坐标,你需要以最快的速度确定这个n维球体的球心坐标,以便于摧毁这个球形空间产生器. Input 第一行是一个整数n(1<=N=10).接下来的n+1行,每行有n个实数,表示球面上一点的n维坐标.每一个实数精确到小数点后6位,且其绝对值都不超过20000. Output 有且只有一行,依次给出球心的n维坐标(n个实数),两个实数之间用一个空格隔开.每个实数精确到

[spoj104][Highways] (生成树计数+矩阵树定理+高斯消元)

In some countries building highways takes a lot of time... Maybe that's because there are many possiblities to construct a network of highways and engineers can't make up their minds which one to choose. Suppose we have a list of cities that can be c

UVA 10828 Back to Kernighan-Ritchie(高斯消元)

高斯消元求概率 对于非起点,期望x[i] = ∑x[j] / deg[j] #include<cstdio> #include<iostream> #include<cstdlib> #include<cstring> #include<string> #include<algorithm> #include<map> #include<queue> #include<vector> #includ