嘟嘟嘟




遇到这种(看似)构造的题,我好像一般都做不出来……




然而这题正解是高斯消元解异或方程组……

首先我们容易列出式子a[i][j] ^ a[i - 1][j] ^ a[i + 1][j] ^ a[i][j - 1] ^ a[i][j + 1] = 0。于是我们列出所有像这样的\(n * m\)个式子,然后\(O((nm) ^ 3)\)高斯消元加bitset优化就过了。




讲真我还不会高斯消元解异或方程组,就现学了一下。其实就是把运算改成了异或,然后bitset可以把一个一个消改成一行和一行消。

#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<vector>
#include<stack>
#include<queue>
#include<ctime>
#include<bitset>
using namespace std;
#define enter puts("")
#define space putchar(' ')
#define Mem(a, x) memset(a, x, sizeof(a))
#define In inline
typedef long long ll;
typedef double db;
const int INF = 0x3f3f3f3f;
const db eps = 1e-8;
const int maxn = 1605;
inline ll read()
{
ll ans = 0;
char ch = getchar(), last = ' ';
while(!isdigit(ch)) last = ch, ch = getchar();
while(isdigit(ch)) ans = (ans << 1) + (ans << 3) + ch - '0', ch = getchar();
if(last == '-') ans = -ans;
return ans;
}
inline void write(ll x)
{
if(x < 0) x = -x, putchar('-');
if(x >= 10) write(x / 10);
putchar(x % 10 + '0');
} int n, m;
const int dx[] = {-1, 0, 1, 0, 0}, dy[] = {0, 1, 0, -1, 0};
bitset<maxn> f[maxn]; In int num(int x, int y)
{
return (x - 1) * m + y;
} int ans[maxn];
In void Gauss(int n)
{
for(int i = 1; i <= n; ++i)
{
int pos = i;
while(pos <= n && !f[pos][i]) ++pos;
if(pos == n + 1) continue;
swap(f[i], f[pos]);
for(int j = i + 1; j <= n; ++j) if(f[j][i]) f[j] ^= f[i];
}
for(int i = n; i; --i)
if(!f[i][i]) ans[i] = 1;
else for(int j = i + 1; j <= n; ++j) if(f[i][j]) ans[i] ^= ans[j];
} int main()
{
n = read(), m = read();
for(int i = 1; i <= n; ++i)
for(int j = 1; j <= m; ++j)
for(int k = 0; k <= 4; ++k)
{
int x = i + dx[k], y = j + dy[k];
if(x < 1 || x > n || y < 1 || y > m) continue;
f[num(i, j)][num(x, y)] = 1;
}
// for(int i = 1; i <= n; ++i) cout << f[i].to_string() << endl;
Gauss(n * m);
for(int i = 1; i <= n; ++i)
{
for(int j = 1; j <= m; ++j) write(ans[num(i, j)]), space;
enter;
}
return 0;
}

[CQOI2014]和谐矩阵的更多相关文章

  1. BZOJ 3503: [Cqoi2014]和谐矩阵( 高斯消元 )

    偶数个相邻, 以n*m个点为变量, 建立异或方程组然后高斯消元... O((n*m)^3)复杂度看起来好像有点大...但是压一下位的话就是O((n*m)^3 / 64), 常数小, 实际也跑得很快. ...

  2. 【高斯消元】BZOJ3503 [Cqoi2014]和谐矩阵

    3503: [Cqoi2014]和谐矩阵 Time Limit: 10 Sec  Memory Limit: 128 MBSec  Special JudgeSubmit: 1197  Solved: ...

  3. BZOJ_3503_[Cqoi2014]和谐矩阵_高斯消元

    BZOJ_3503_[Cqoi2014]和谐矩阵_高斯消元 题意: 我们称一个由0和1组成的矩阵是和谐的,当且仅当每个元素都有偶数个相邻的1.一个元素相邻的元素包括它本身,及他上下左右的4个元素(如果 ...

  4. bzoj千题计划105:bzoj3503: [Cqoi2014]和谐矩阵(高斯消元法解异或方程组)

    http://www.lydsy.com/JudgeOnline/problem.php?id=3503 b[i][j] 表示i对j是否有影响 高斯消元解异或方程组 bitset优化 #include ...

  5. 3503: [Cqoi2014]和谐矩阵

    3503: [Cqoi2014]和谐矩阵 链接 分析: 对于每个点,可以列出一个方程a[i][j]=a[i][j-1]^a[i][j+1]^a[i-1][j]^a[i+1][j],于是可以列出n*m个 ...

  6. P3164 [CQOI2014]和谐矩阵

    P3164 [CQOI2014]和谐矩阵 乱写能AC,暴力踩标程(雾 第一眼 诶这题能暴力枚举2333!!! 第二眼 诶这题能高斯消元!那只需要把每个位置的数给设出来就能够列方程了!然后就可以\(O( ...

  7. BZOJ3503:[CQOI2014]和谐矩阵(高斯消元,bitset)

    Description 我们称一个由0和1组成的矩阵是和谐的,当且仅当每个元素都有偶数个相邻的1.一个元素相邻的元素包括它本 身,及他上下左右的4个元素(如果存在). 给定矩阵的行数和列数,请计算并输 ...

  8. Luogu3164 CQOI2014 和谐矩阵 异或高斯消元

    传送门 题意:给出$N,M$,试构造一个$N \times M$的非全$0$矩阵,其中所有格子都满足:它和它上下左右四个格子的权值之和为偶数.$N , M \leq 40$ 可以依据题目中的条件列出有 ...

  9. bzoj 3503: [Cqoi2014]和谐矩阵【高斯消元】

    如果确定了第一行,那么可以推出来整个矩阵,矩阵合法的条件是n+1行全是0 所以推出来n+1行和1行的关系,然后用异或高斯消元来解即可 #include<iostream> #include ...

  10. P3164 [CQOI2014]和谐矩阵(高斯消元 + bitset)

    题意:构造一个$n*m$矩阵 使得每个元素和上下左右的xor值=0 题解:设第一行的每个元素值为未知数 可以依次得到每一行的值 然后把最后一行由题意条件 得到$m$个方程 高斯消元解一下 bitset ...

随机推荐

  1. Android Studio 学习(二) UI

    TextView android:gravity="center"居中对齐 //文字对齐方式 top bottom left right center android:textSi ...

  2. laravel中请求用例$request可用的一些方法小结

    laravel中$request可用的一些方法小结 1,请求方法的获取 $method = $request->method(); 2,检测请求方法 $res = $request->is ...

  3. Andorid 刷新样式一

    一.Gradle中的Build.gradle依赖项目 compile 'com.github.moduth:blockcanary-android:1.1.0' debugCompile 'com.s ...

  4. js 判断数组中的值是否都相等

    function isAllEqual(array) { if (array.length > 0) { return !array.some(function(value, index) { ...

  5. html 获取数据并发送给后端方式

    一.方式一 使用ajax提交 function detailed() { var date = $("#asset_ip").text() $.ajax({ url: " ...

  6. Python函数式编程(二):常见高级函数

    一个函数的参数中有函数作为参数,这个函数就为高级函数. 下面学习几个常见高级函数. ---------------------------------------------------------- ...

  7. mac os安装多个版本的chrome

    1.下载chrome69安装程序后,双击dmg文件 2.将chrome拖到Application文件夹,如图,选择保留两者,不要替换 打开应用程序,会多出一个Google Chrome2,重命名为Go ...

  8. springboot 学习之路 2(注解介绍)

    目录:[持续更新.....] spring 部分常用注解 spring boot 学习之路1(简单入门) spring boot 学习之路2(注解介绍) spring boot 学习之路3( 集成my ...

  9. openstack Ocata版本 python

    from keystoneauth1.identity import v3 from keystoneauth1 import session from novaclient import clien ...

  10. [20180904]工作中一个错误.txt

    [20180904]工作中一个错误.txt --//昨天看我提交一份修改建议,发现自己写的sql语句存在错误.--//链接:http://blog.itpub.net/267265/viewspace ...