1 条题解
-
0
外星千足虫(Alien Millipede) 题解
思路分析
按题目要求使用对应数据结构与算法模拟/递推求解,注意数据范围边界与时间复杂度。
参考代码
#include <algorithm> #include <bitset> #include <iostream> #include <string> #include <vector> using namespace std; const int MAXN = 1005; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n, m; if (!(cin >> n >> m)) return 0; vector<bitset<MAXN>> mat(m); for (int i = 0; i < m; ++i) { string s; int b; cin >> s >> b; for (int j = 0; j < n; ++j) { if (s[j] == '1') mat[i].set(j); } if (b) mat[i].set(n); } int max_row_used = 0; for (int col = 0; col < n; ++col) { int piv = -1; for (int i = col; i < m; ++i) { if (mat[i].test(col)) { piv = i; break; } } if (piv == -1) { cout << "Cannot Determine\n"; return 0; } max_row_used = max(max_row_used, piv + 1); swap(mat[col], mat[piv]); for (int i = 0; i < m; ++i) { if (i != col && mat[i].test(col)) { mat[i] ^= mat[col]; } } } cout << max_row_used << "\n"; for (int i = 0; i < n; ++i) { cout << (mat[i].test(n) ? "?y7M#\n" : "Earth\n"); } return 0; }
- 1
信息
- ID
- 8607
- 时间
- 1000ms
- 内存
- 512MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者