zoukankan      html  css  js  c++  java
  • HDU 3915 Game (高斯消元)

    题意:有n堆石子,每个人只能从某一堆至少拿走一个,不能拿者败。问事先拿走某些堆的石子,使得先手必败。

    析:将石子拆成二进制,未知数为1表示保留该堆石子,为0表示事先拿走该堆石子。最后求自由变元的数目,就是2的幂。

    代码如下:

    #pragma comment(linker, "/STACK:1024000000,1024000000")
    #include <cstdio>
    #include <string>
    #include <cstdlib>
    #include <cmath>
    #include <iostream>
    #include <cstring>
    #include <set>
    #include <queue>
    #include <algorithm>
    #include <vector>
    #include <map>
    #include <cctype>
    #include <cmath>
    #include <stack>
    #include <sstream>
    #define debug() puts("++++");
    #define gcd(a, b) __gcd(a, b)
    #define lson l,m,rt<<1
    #define rson m+1,r,rt<<1|1
    #define freopenr freopen("in.txt", "r", stdin)
    #define freopenw freopen("out.txt", "w", stdout)
    using namespace std;
    
    typedef long long LL;
    typedef unsigned long long ULL;
    typedef pair<int, int> P;
    const int INF = 0x3f3f3f3f;
    const double inf = 0x3f3f3f3f3f3f;
    const double PI = acos(-1.0);
    const double eps = 1e-8;
    const int maxn = 100 + 10;
    const int mod = 1000007;
    const int dr[] = {-1, 0, 1, 0};
    const int dc[] = {0, 1, 0, -1};
    const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
    int n, m;
    const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    inline bool is_in(int r, int c){
      return r >= 0 && r < n && c >= 0 && c < m;
    }
    int equ, var, free_num;
    bool a[maxn][maxn];
    
    int Gauss(){
      int max_r, col, k;
      free_num = 0;
      for(k = col = 0; k < equ && col < var; ++k, ++col){
        max_r = k;
        for(int i = k+1; i < equ; ++i)
          if(a[i][col] > a[max_r][col])  max_r = i;
        if(a[max_r][col] == 0){
          --k;
          ++free_num;  continue;
        }
        if(max_r != k){
          for(int i = col; i <= var; ++i)
            swap(a[k][i], a[max_r][i]);
        }
        for(int i = k+1; i < equ; ++i)  if(a[i][col])
          for(int j = col; j <= var; ++j)
            a[i][j] ^= a[k][j];
      }
      return var - k;
    }
    
    int main(){
      int T;  cin >> T;
      while(T--){
        scanf("%d", &n);
        for(int i = 0; i < n; ++i){
          scanf("%d", &m);
          for(int j = 0; j < 31; ++j)  a[j][i] = (m&(1<<j));
        }
        for(int i = 0; i < 31; ++i)  a[i][n] = 0;
        equ = 31;  var = n;
        int t = Gauss();
        int ans = 1;
        for(int i = 0; i < t; ++i)
          ans = ans * 2 % mod;
        printf("%d
    ", ans);
      }
      return 0;
    }
    

      

  • 相关阅读:
    asp.net mvc 两级分类联动方法示例
    动手实践虚拟网络
    KVM 网络虚拟化基础
    LVM 类型的 Storage Pool
    KVM 存储虚拟化
    CPU 和内存虚拟化原理
    远程管理 KVM 虚机
    启动第一个 KVM 虚机
    准备 KVM 实验环境
    虚拟化
  • 原文地址:https://www.cnblogs.com/dwtfukgv/p/6683999.html
Copyright © 2011-2022 走看看