A.黑白配
思路:
n个学生手心和手背分为2个组求出他们的差直接按题意写即可
Code:
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; for (int i = 0; i < n; ++i) { int cnt1 = 0, cnt0 = 0; for (int j = 0, x; j < m; ++j) { cin >> x; if (x) cnt1++; else cnt0++; } cout << abs(cnt1 - cnt0) << '\n'; } }
B.映射
思路:
每个位置的p[a[i]]与b[i]不冲突输出Yes 冲突输出No 按题意来
Code:
#include <bits/stdc++.h> using namespace std; void solve() { int n; cin >> n; vector<int> a(n), b(n); for (int& i : a) cin >> i; for (int& i : b) cin >> i; vector<int> p(n + 1, -1); for (int i = 0; i < n; i++) { if (p[a[i]] == -1 || p[a[i]] == b[i]) { p[a[i]] = b[i]; } else { cout << "No\n"; return ; } } cout << "Yes\n"; return ; } int main() { ios::sync_with_stdio(false); cin.tie(0);cout.tie(0); int t; cin >> t; while (t--) { solve(); } return 0; }
C.马走日
思路:
统计马(1, 1)开始可以出现的点的个数 四个特判 我们假设n <= m 我们就会考虑1 2 (3, 3) ..这四个情况 n = 1很明显马跳不动所以是1 n = 2很明显只能在2的区域动 (m + 1) / 2 n = 3 m = 3这个中间取不到 .. n * m
Code:
#include <bits/stdc++.h> using namespace std; using i64 = long long; void solve() { i64 n, m; cin >> n >> m; if (n > m) { swap(n, m); } if (n == 1) { cout << 1 << '\n'; } else if (n == 2) { cout << (m + 1) / 2 << '\n'; } else if (n == 3 && m == 3) { cout << 8 << '\n'; } else { cout << n * m << '\n'; } } int main() { int t; cin >> t; while (t--) { solve(); } return 0; }
标签:练习赛,cout,int,++,cin,牛客,122,solve,using From: https://www.cnblogs.com/youhualiuh/p/18048042