[洛谷P2447][SDOI2010]外星千足虫

题目大意:有$n$个数,每个数为$0$或$1$,给你其中一些关系,一个关系形如其中几个数的异或和是多少,问最少知道前几个关系就可以得出每个数是什么,并输出每个数

题解:异或方程组,和高斯消元差不多,就是把加减改成了异或。

卡点:用$bitset$优化,输出时输反了

 

C++ Code:

#include <algorithm>
#include <iostream>
#include <bitset>
#define maxn 1010
#define maxm 2010
int n, m, ans;
std::bitset<maxn> s[maxm];
int main() {
	std::ios::sync_with_stdio(false), std::cin.tie(0), std::cout.tie(0);
	std::cin >> n >> m;
	for (int i = 1, x; i <= m; i++) {
		std::cin >> s[i] >> x;
		s[i] <<= 1; s[i][n + 1] = x;
	}
	for (int i = 1, pos; i <= n; i++) {
		for (pos = i; pos <= m; pos++) if (s[pos][i]) break;
		if (pos > m) {
			std::cout << "Cannot Determine\n";
			return 0;
		}
		ans = std::max(ans, pos);
		std::swap(s[i], s[pos]);
		for (int j = 1; j <= m; j++) if (i != j && s[j][i]) s[j] ^= s[i];
	}
	std::cout << ans << '\n';
	for (int i = n; i; i--) std::cout << (s[i][n + 1] ? "?y7M#\n" : "Earth\n");
	return 0;
}

  

转载于:https://www.cnblogs.com/Memory-of-winter/p/10048649.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值