题意:n个灯,m个开关,给定每个开关控制的灯,全部的灯初始时全部熄灭,开关按一下其所控制的灯的状态全部反转,开关最多只能按一下。问达到目标状态的方案数。

思路:xor方程组的模型。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/* ******************************************************************************** */
#include <iostream>                                                                 //
#include <cstdio>                                                                   //
#include <cmath>                                                                    //
#include <cstdlib>                                                                  //
#include <cstring>                                                                  //
#include <vector>                                                                   //
#include <ctime>                                                                    //
#include <deque>                                                                    //
#include <queue>                                                                    //
#include <algorithm>                                                                //
#include <map>                                                                      //
#include <cmath>                                                                    //
using namespace std;                                                                //
                                                                                    //
#define pb push_back                                                                //
#define mp make_pair                                                                //
#define X first                                                                     //
#define Y second                                                                    //
#define all(a) (a).begin(), (a).end()                                               //
#define fillchar(a, x) memset(a, x, sizeof(a))                                      //
                                                                                    //
typedef pair<intint> pii;                                                         //
typedef long long ll;                                                               //
typedef unsigned long long ull;                                                     //
                                                                                    //
#ifndef ONLINE_JUDGE                                                                //
void RI(vector<int>&a,int n){a.resize(n);for(int i=0;i<n;i++)scanf("%d",&a[i]);}    //
void RI(){}void RI(int&X){scanf("%d",&X);}template<typename...R>                    //
void RI(int&f,R&...r){RI(f);RI(r...);}void RI(int*p,int*q){int d=p<q?1:-1;          //
while(p!=q){scanf("%d",p);p+=d;}}void print(){cout<<endl;}template<typename T>      //
void print(const T t){cout<<t<<endl;}template<typename F,typename...R>              //
void print(const F f,const R...r){cout<<f<<", ";print(r...);}template<typename T>   //
void print(T*p, T*q){int d=p<q?1:-1;while(p!=q){cout<<*p<<", ";p+=d;}cout<<endl;}   //
#endif // ONLINE_JUDGE                                                              //
template<typename T>bool umax(T&a, const T&b){return b<=a?false:(a=b,true);}        //
template<typename T>bool umin(T&a, const T&b){return b>=a?false:(a=b,true);}        //
template<typename T>                                                                //
void V2A(T a[],const vector<T>&b){for(int i=0;i<b.size();i++)a[i]=b[i];}            //
template<typename T>                                                                //
void A2V(vector<T>&a,const T b[]){for(int i=0;i<a.size();i++)a[i]=b[i];}            //
                                                                                    //
const double PI = acos(-1.0);                                                       //
const int INF = 1e9 + 7;                                                            //
                                                                                    //
/* -------------------------------------------------------------------------------- */
 
struct XorElimination {
    const static int maxn = 55;
    bool A[maxn][maxn];
    int solve(int m, int n) {
        int i = 0, j = 0, k, r, u;
        while (i < m && j < n) {
            r = i;
            for (k = i; k < m; k ++) {
                if (A[k][j]) {
                    r = k;
                    break;
                }
            }
            if (A[r][j]) {
                if (r != i) for (k = 0; k <= n; k ++) swap(A[r][k], A[i][k]);
                for (int u = i + 1; u < m; u ++) {
                    if (A[u][j]) {
                        for (k = i; k <= n; k ++) A[u][k] ^= A[i][k];
                    }
                }
                i ++;
            }
            j ++;
        }
        /** 返回自由变元个数,无解返回-1 **/
        for (int i = 0; i < m; i ++) {
            if (A[i][n]) {
                bool ok = false;
                for (int j = 0;  j < n; j ++) {
                    if (A[i][j]) {
                        ok = true;
                        break;
                    }
                }
                if (!ok) return -1;
            }
        }
        return n - i;
    }
};/** 下标从0开始 **/
 
XorElimination solver;
bool buf[55][55];
int main() {
#ifndef ONLINE_JUDGE
    freopen("in.txt""r", stdin);
#endif // ONLINE_JUDGE
    int T, n, m, cas = 0;
    cin >> T;
    while (T --) {
        cin >> n >> m;
        memset(buf, 0, sizeof(buf));
        for (int i = 0; i < m; i ++) {
            int x, y;
            scanf("%d", &x);
            for (int j = 0; j < x; j ++) {
                scanf("%d", &y);
                buf[y - 1][i] = true;
            }
        }
        printf("Case %d:\n", ++ cas);
        int q;
        cin >> q;
        while (q --) {
            for (int i = 0; i < n; i ++) {
                for (int j = 0; j < m; j ++) {
                    solver.A[i][j] = buf[i][j];
                }
            }
            for (int i = 0; i < n; i ++) {
                int x;
                scanf("%d", &x);
                solver.A[i][m] = x;
            }
            int r = solver.solve(n, m);
            cout << (~r? (1ll << r) : 0) << endl;
        }
    }
    return 0;
}
/* ******************************************************************************** */

[hdu3364]xor方程组消元的更多相关文章

  1. xor方程组消元 UVA 11542 Square

    题目传送门 题意:给n个数,选择一些数字乘积为平方数的选择方案数.训练指南题目. 分析:每一个数字分解质因数.比如4, 6, 10, 15,, , , , 令,表示选择第i个数字,那么,如果p是平方数 ...

  2. ACM学习历程—SGU 275 To xor or not to xor(xor高斯消元)

    题目链接:http://acm.sgu.ru/problem.php?contest=0&problem=275 这是一道xor高斯消元. 题目大意是给了n个数,然后任取几个数,让他们xor和 ...

  3. bzoj 2115: [Wc2011] Xor xor高斯消元

    2115: [Wc2011] Xor Time Limit: 10 Sec  Memory Limit: 259 MBSubmit: 797  Solved: 375[Submit][Status] ...

  4. ACM学习历程—HDU 3915 Game(Nim博弈 && xor高斯消元)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3915 题目大意是给了n个堆,然后去掉一些堆,使得先手变成必败局势. 首先这是个Nim博弈,必败局势是所 ...

  5. ACM学习历程—UESTC 1219 Ba Gua Zhen(dfs && 独立回路 && xor高斯消元)

    题目链接:http://acm.uestc.edu.cn/#/problem/show/1219 题目大意是给了一张图,然后要求一个点通过路径回到这个点,使得xor和最大. 这是CCPC南阳站的一道题 ...

  6. ACM学习历程—BZOJ 2115 Xor(dfs && 独立回路 && xor高斯消元)

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2115 题目大意是求一条从1到n的路径,使得路径xor和最大. 可以发现想枚举1到n的所有路 ...

  7. ACM学习历程—HDU 3949 XOR(xor高斯消元)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3949 题目大意是给n个数,然后随便取几个数求xor和,求第k小的.(重复不计算) 首先想把所有xor的 ...

  8. SGU 275 To xor or not to xor 高斯消元求N个数中选择任意数XORmax

    275. To xor or not to xor   The sequence of non-negative integers A1, A2, ..., AN is given. You are ...

  9. hdu3949 XOR xor高斯消元

    XOR Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...

随机推荐

  1. 通达OA任意用户登录 漏洞复现

    0x00 漏洞简介 通达OA国内常用的办公系统,使用群体,大小公司都可以,其此次安全更新修复的高危漏洞为任意用户登录漏洞.攻击者在远程且未经授权的情况下,通过利用此漏洞,可以直接以任意用户身份登录到系 ...

  2. 详解 DatagramSocket类

    (请观看本人博文 -- <详解 网络编程>) DatagramSocket 概述: 这类代表一个发送和接收数据包的插座. 该类是遵循 UDP协议 实现的一个Socket类. 数据报套接字发 ...

  3. selemiun 下拉菜单、复选框、弹框定位识别

    一.下拉菜单识别 对下拉框的操作,主要是通过Select 类里面的方法来实现的,所以需要new 一个Select 对象(org.openqa.selenium.support.ui.Select)来进 ...

  4. 立体匹配-----NCC视差匹配

    目录 一.立体匹配算法 1.立体匹配算法分类 二.NCC 视差匹配方法 1.原理 2.NCC计算公式 3.算法流程 4.代码实现     5.不同场景运行 三.结论 四.遇到的问题及解决方法 一.立体 ...

  5. 用python把技术文档中,每个模块系列截图生成一个动态GIF

    前言 本文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,版权归原作者所有,如有问题请及时联系我们以作处理. 最近在写技术文档的时候,发现一个问题.对于每个技术步骤,都需要一个截图,这 ...

  6. ERROR 2003 (HY000): Can't connect to MySQL server on '192.168.33.10' (111) 解决方法

    谷歌了一下之后,原来是在mysql的my.cnf中有下面一段代码: # Instead of skip-networking the default is now to listen only on ...

  7. Docker数据管理(一)

    数据卷挂载 在生产环境中,需要对数据进行持久化,冗余化,或者在需要在多个容器之间进行数据共享 数据卷:容器内数据直接映射到本地主机环境 数据卷容器:使同特定容器维护数据卷 -v 进行映射 1.在容器内 ...

  8. 2019-2020-1 20199329《Linux内核原理与分析》第五周作业

    <Linux内核原理与分析>第五周作业 一.上周问题总结: 虚拟机将c文件汇编成汇编文件时忘记添加include<stdio.h> gdb跟踪汇编过程不熟练 二.本周学习内容: ...

  9. java并发中CountDownLatch的使用

    文章目录 主线程等待子线程全都结束之后再开始运行 等待所有线程都准备好再一起执行 停止CountdownLatch的await java并发中CountDownLatch的使用 在java并发中,控制 ...

  10. Scala教程之:可变和不变集合

    文章目录 mutable HashMap immutable HashMap 集合在程序中是非常有用的,只有用好集合才能真正感受到该语言的魅力.在scala中集合主要在三个包里面:scala.coll ...