【题目链接】

http://poj.org/problem?id=1830

【算法】

列出异或方程组,用高斯消元求解

【代码】

#include <algorithm>
#include <bitset>
#include <cctype>
#include <cerrno>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <limits>
#include <list>
#include <map>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <utility>
#include <vector>
#include <cwchar>
#include <cwctype>
#include <stack>
#include <limits.h>
using namespace std; int i,j,k,T,n,x,y,ans;
int a[]; int main()
{ scanf("%d",&T);
while (T--)
{
scanf("%d",&n);
for (i = ; i <= n; i++) scanf("%d",&a[i]);
for (i = ; i <= n; i++)
{
scanf("%d",&x);
a[i] ^= x;
a[i] |= ( << i);
}
while (scanf("%d%d",&x,&y) && x && y) a[y] |= ( << x);
ans = ;
for (i = ; i <= n; i++)
{
for (j = i + ; j <= n; j++)
{
if (a[j] > a[i])
swap(a[i],a[j]);
}
if (a[i] == )
{
ans = << (n - i + );
break;
}
if (a[i] == )
{
ans = ;
break;
}
for (k = n; k; k--)
{
if (a[i] & ( << k))
{
for (j = ; j <= n; j++)
{
if (i != j && (a[j] & ( << k)))
a[j] ^= a[i];
}
break;
}
}
}
if (!ans) printf("Oh,it's impossible~!!\n");
else printf("%d\n",ans);
} return ; }

【POJ 1830】 开关问题的更多相关文章

  1. POJ 1830 开关问题(高斯消元)题解

    思路:乍一看好像和线性代数没什么关系.我们用一个数组B表示第i个位置的灯变了没有,然后假设我用u[i] = 1表示动开关i,mp[i][j] = 1表示动了i之后j也会跟着动,那么第i个开关的最终状态 ...

  2. POJ 1830 开关问题 【01矩阵 高斯消元】

    任意门:http://poj.org/problem?id=1830 开关问题 Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 1 ...

  3. POJ 1830 开关问题(高斯消元求解的情况)

    开关问题 Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 8714   Accepted: 3424 Description ...

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

    http://poj.org/problem?id=1830 如果开关s1操作一次,则会有s1(记住自己也会变).和s1连接的开关都会做一次操作. 那么设矩阵a[i][j]表示按下了开关j,开关i会被 ...

  5. poj 1830 开关问题

    开关问题 题意:给n(0 < n < 29)开关的初始和最终状态(01表示),以及开关之间的关联关系(关联关系是单向的输入a b表示a->b),问有几种方式得到最终的状态.否则输出字 ...

  6. POJ 1830 开关问题(Gauss 消元)

    开关问题 Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 7726   Accepted: 3032 Description ...

  7. POJ 1830 开关问题 (高斯消元)

    题目链接 题意:中文题,和上篇博客POJ 1222是一类题. 题解:如果有解,解的个数便是2^(自由变元个数),因为每个变元都有两种选择. 代码: #include <iostream> ...

  8. POJ 1830.开关问题(高斯消元)

    题目链接 Solutin: 将每个开关使用的情况当成未知数,如果开关i能影响到开关j,那么系数矩阵A[j][i]的系数为1. 每个开关增广矩阵的值是开关k的初状态异或开关k的目标状态,这个应该很容易想 ...

  9. POJ 1830 开关问题 [高斯消元XOR]

    和上两题一样 Input 输入第一行有一个数K,表示以下有K组测试数据. 每组测试数据的格式如下: 第一行 一个数N(0 < N < 29) 第二行 N个0或者1的数,表示开始时N个开关状 ...

  10. POJ.1830.开关问题(高斯消元 异或方程组)

    题目链接 显然我们需要使每个i满足\[( ∑_{j} X[j]*A[i][j] ) mod\ 2 = B[i]\] 求这个方程自由元Xi的个数ans,那么方案数便是\(2^{ans}\) %2可以用^ ...

随机推荐

  1. dell inspiron 15 3000 装XP win7 等GHOST系统方法

    dell inspiron 装XP win7 等GHOST系统方法 . 开机按F2,进入BIOS .在 BIOS 的Boot菜单下,将Secure Boot 改为 Disabled . 将Boot L ...

  2. VHDL之concurrent之generate

    GENERATE It is another concurrent statement (along with operators and WHEN). It is equivalent to the ...

  3. C#:winform项目在win7,xp32位和64位都能运行

    vs中项目配置管理器活动解决方案平台选择X86平台.

  4. 09--c++ 类的继承与派生

    c++ 类的继承与派生   一.基本概念 1.类的继承,是新的类从已有类那里得到已有的特性.或从已有类产生新类的过程就是类的派生.原有的类称为基类或父类,产生的新类称为派生类或子类.   2.派生类的 ...

  5. 【sqli-labs】 less5 GET - Double Injection - Single Quotes - String (双注入GET单引号字符型注入)

    双注入查询可以查看这两篇介绍 https://www.2cto.com/article/201302/190763.html https://www.2cto.com/article/201303/1 ...

  6. php 加密解密函数封装

    算法一: //加密函数 function lock_url($txt,$key='yang') { $chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghi ...

  7. webpack学习(三)

    前篇:webpack学习(二) jquery不需要在项目中自己下载,而是作为一个模块引入.jquery的存放路径是在 node_modules目录下.1.首先给项目安装jquery,npm insta ...

  8. 团体程序设计天梯赛-练习集-L1-038. 新世界

    L1-038. 新世界 这道超级简单的题目没有任何输入. 你只需要在第一行中输出程序员钦定名言“Hello World”,并且在第二行中输出更新版的“Hello New World”就可以了. #in ...

  9. python tips:类的绑定方法(bound)和非绑定方法(unbound)

    类属性只有类及其实例能够访问,可以理解为一个独立的命名空间. Python中类属性的引用方式有两种: 1. 通过类的实例进行属性引用,称为绑定方法(bound method),可以理解为方法与实例绑定 ...

  10. spring学习地址

    http://developer.51cto.com/art/201006/205212_2.htm