hdu 5088 高斯消元n堆石子取k堆石子使剩余异或值为0

http://acm.hdu.edu.cn/showproblem.php?pid=5088

求能否去掉几堆石子使得nim游戏胜利

我们可以把题目转化成求n堆石子中的k堆石子数异或为0的情况数。使用x1---xn表示最终第i堆石子到底取不取(1取,0不取),将每堆石子数画成2进制的形式,列成31个方程来求自由变元数,最后由于自由变元能取1、0两种状态,所以自由变元数多于0即可输出Yes。

注意有40+个方程,因为A[I]<=1e12....

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <queue>
#include <map>
#include <iostream>
#include <algorithm>
using namespace std;
#define RD(x) scanf("%d",&x)
#define RD2(x,y) scanf("%d%d",&x,&y)
#define RD3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define clr0(x) memset(x,0,sizeof(x))
#define clr1(x) memset(x,-1,sizeof(x))
#define eps 1e-9
const double pi = acos(-1.0);
typedef long long LL;
typedef unsigned long long ULL;
const int modo = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const int inf = 0x3fffffff;
const LL _inf = 1e18;
const int maxn = 1005,maxm = 10005;

#define MAXN 1100
#define MOD 1000007
#define weishu 42
LL a[MAXN], g[MAXN][MAXN];
int Gauss(int n) {
    int i, j, r, c, cnt;
    for (c = cnt = 0; c < n; c++) {
        for (r = cnt; r < weishu; r++) {
            if (g[r][c])
                break;
        }
        if (r < weishu) {
            if (r != cnt) {
                for (i = 0; i < n; i++)
                    swap(g[r][i], g[cnt][i]);
            }
            for (i = cnt + 1; i < weishu; i++) {
                if (g[i][c]) {
                    for (j = 0; j < n; j++)
                        g[i][j] ^= g[cnt][j];
                }
            }
            cnt++;
        }
    }
    return n - cnt;
}
int main() {
    int c;
    int n, i, j;
    int ans, vary;
    scanf("%d", &c);
    while (c--) {
        int fuck = 0;
        scanf("%d", &n);
        for (i = 0; i < n; i++){
            scanf("%I64d", &a[i]);
            fuck ^= a[i];
        }
        for (i = 0; i < weishu; i++) {
            for (j = 0; j < n; j++)
                g[i][j] = (a[j] >> i) & 1;
        }
        vary = Gauss(n);
        //printf("%d\n", vary);
        if(vary <= 0 )//|| (fuck == 0 && vary <= 1))
            puts("No");
        else
            puts("Yes");

    }
    return 0;
}
时间: 2025-01-02 18:48:19

hdu 5088 高斯消元n堆石子取k堆石子使剩余异或值为0的相关文章

hdu 3915 高斯消元

Game Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 724    Accepted Submission(s): 285 Problem Description Mr.Frost is a child who is too simple, sometimes naive, always plays some simple but i

hdu 2262 高斯消元求期望

Where is the canteen Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 1070    Accepted Submission(s): 298 Problem Description After a long drastic struggle with himself, LL decide to go for some

hdu 4418 高斯消元求期望

Time travel Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1480    Accepted Submission(s): 327 Problem Description Agent K is one of the greatest agents in a secret organization called Men in B

HDU 3359 高斯消元模板题,

http://acm.hdu.edu.cn/showproblem.php?pid=3359 题目的意思是,由矩阵A生成矩阵B的方法是: 以a[i][j]为中心的,哈曼顿距离不大于dis的数字的总和 / 个数,就是矩阵B的b[i][j] 现在给出B,要求A 那么我们设A矩阵为a[1][1], a[1][2], a[1][3]..... 那么对于每一个b[i][j]我们有b[i][j] = (a[1][1] + a[1][2] + ... + ) / cnt 所以这样可以建议一条方程,然后guas

HDU 4418 高斯消元解决概率期望

题目大意: 一个人在n长的路径上走到底再往回,走i步停下来的概率为Pi , 求从起点开始到自己所希望的终点所走步数的数学期望 因为每个位置都跟后m个位置的数学期望有关 E[i] = sigma((E[i+j]+j)*P[j]) 我们需要将模型转化一下,本来路径为012345这样,因为来回走,我们多定义n-2个点就是 0123454321然后利用取模就可以不断找到下一组相关的m个点 列出多元方程组,利用高斯消元解决问题 1 #include <cstdio> 2 #include <cst

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

【BZOJ-1923】外星千足虫 高斯消元 + xor方程组

1923: [Sdoi2010]外星千足虫 Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 766  Solved: 485[Submit][Status][Discuss] Description Input 第一行是两个正整数 N, M. 接下来 M行,按顺序给出 Charles 这M次使用“点足机”的统计结果.每行包含一个“01”串和一个数字,用一个空格隔开.“01”串按位依次表示每只虫子是否被放入机器:如果第 i 个字符是“0”则代表编号为

【概率DP/高斯消元】BZOJ 2337:[HNOI2011]XOR和路径

2337: [HNOI2011]XOR和路径 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 682  Solved: 384[Submit][Status][Discuss] Description 几乎是一路看题解过来了.. 拖了一个星期的题目- - 已然不会概率DP(说得好像什么时候会过一样),高斯消元(打一次copy一遍). 发现异或题目的新解决方法:按位处理.. 发现DP新方法:高斯消元. f[k][i]代表第k位权值起点为i到终点时答案

POJ EXTENDED LIGHTS OUT 1222【高斯消元】

Language: Default EXTENDED LIGHTS OUT Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 7672   Accepted: 4996 Description In an extended version of the game Lights Out, is a puzzle with 5 rows of 6 buttons each (the actual puzzle has 5 row