From 7ee05130ad1030e2b913d2e4c86c9d02aad81e91 Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Tue, 10 May 2022 15:17:59 +0800 Subject: [PATCH] =?UTF-8?q?884.=20=E9=AB=98=E6=96=AF=E6=B6=88=E5=85=83?= =?UTF-8?q?=E8=A7=A3=E5=BC=82=E6=88=96=E7=BA=BF=E6=80=A7=E6=96=B9=E7=A8=8B?= =?UTF-8?q?=E7=BB=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://www.acwing.com/problem/content/submission/code_detail/14082659/ --- AcWing/884/884.cpp | 89 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 AcWing/884/884.cpp diff --git a/AcWing/884/884.cpp b/AcWing/884/884.cpp new file mode 100644 index 00000000..138f011e --- /dev/null +++ b/AcWing/884/884.cpp @@ -0,0 +1,89 @@ +#include +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 105; + +int n, a[N][N]; + +int gauss() { + int c, r; + + for (c = r = 1; c <= n; c++) { + int t = r; + + for (int i = r; i <= n; i++) { + if (a[i][c]) t = i; + } + + if (!a[t][c]) continue; + + std::swap(a[t], a[r]); + + for (int i = r + 1; i <= n; i++) { + if (a[i][c]) { + for (int j = n + 1; j >= c; j--) { + a[i][j] ^= a[r][j]; + } + } + } + + r++; + } + + if (r <= n) { + for (int i = r; i <= n; i++) { + if (a[i][n + 1]) { + return -1; + } + } + + return 1; + } + + for (int i = n; i; i--) { + for (int j = i + 1; j <= n; j++) { + a[i][n + 1] ^= a[i][j] & a[j][n + 1]; + } + } + + return 0; +} + +int main() { + std::ios::sync_with_stdio(false); + + cin >> n; + + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= n + 1; j++) { + cin >> a[i][j]; + } + } + + switch (gauss()) { + case 0: { + for (int i = 1; i <= n; i++) { + cout << a[i][n + 1] << endl; + } + + break; + } + case 1: { + cout << "Multiple sets of solutions" << endl; + + break; + } + case -1: { + cout << "No solution" << endl; + + break; + } + } + + return 0; +}