标签:name span ++ func mat return print tac exception
【题目链接】
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[100]; int main() { scanf("%d",&T); while (T--) { scanf("%d",&n); for (i = 1; i <= n; i++) scanf("%d",&a[i]); for (i = 1; i <= n; i++) { scanf("%d",&x); a[i] ^= x; a[i] |= (1 << i); } while (scanf("%d%d",&x,&y) && x && y) a[y] |= (1 << x); ans = 1; for (i = 1; i <= n; i++) { for (j = i + 1; j <= n; j++) { if (a[j] > a[i]) swap(a[i],a[j]); } if (a[i] == 0) { ans = 1 << (n - i + 1); break; } if (a[i] == 1) { ans = 0; break; } for (k = n; k; k--) { if (a[i] & (1 << k)) { for (j = 1; j <= n; j++) { if (i != j && (a[j] & (1 << k))) a[j] ^= a[i]; } break; } } } if (!ans) printf("Oh,it‘s impossible~!!\n"); else printf("%d\n",ans); } return 0; }
标签:name span ++ func mat return print tac exception
原文地址:https://www.cnblogs.com/evenbao/p/9288552.html