AtCoder Beginner Contest 086
A
模拟题,也可以当成讨论题做。
1 2 3 4 5 6 7 8 9 10 11 12 #include <bits/stdc++.h> using namespace std;int main () { int a,b; while (cin>>a>>b){ if ((a*b)%2 ==0 ) cout<<"Even" <<endl; else cout<<"Odd" <<endl; } return 0 ; }
B
模拟题。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 #include <bits/stdc++.h> using namespace std;const int N = 1e6 + 5 ;typedef long long LL;int a, b;int get (int num) { int res = 0 ; while (num) { res++; num /= 10 ; } return res; } int main () { cin >> a >> b; int c = a * pow (10 ,get (b) ) + b; for (int i = 1 ; i <= sqrt (c); i++) { if (i * i == c) { cout << "Yes" << endl; return 0 ; } } cout << "No" << endl; return 0 ; }
C
需要判断步数够不够,步数够的前提下需要保整奇偶数性质满足。自己手玩一下即可。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 #include <bits/stdc++.h> using namespace std;const int N = 1e6 + 5 ;typedef long long LL;int n;int main () { cin >> n; int nowx = 0 , nowy = 0 , nowt = 0 ; int flag = 0 ; while (n--) { int x, y, t; cin >> t >> x >> y; if ((abs (x - nowx) + abs (y - nowy) > (t - nowt)) || (((t - nowt) - abs (x - nowx) - abs (y - nowy)) % 2 == 1 )) { flag = 1 ; } nowx = x, nowy = y, nowt = t; } if (flag) cout << "No" << endl; else cout << "Yes" << endl; return 0 ; }
D
由于是以2k
为周期不断重复的,因此可以直接取模,然后由于黑白又是相间的,因此可以只计算黑色的,之后枚举每个矩形,考虑优化的话就是直接使用前缀和去枚举分界点。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 #include <iostream> #include <cstdio> using namespace std;const int K = 2005 ;int sum[K][K];inline int calc (int x1, int y1, int x2, int y2) {return sum[x2][y2] - sum[x2][y1 - 1 ] - sum[x1 - 1 ][y2] + sum[x1 - 1 ][y1 - 1 ];}int main () { ios::sync_with_stdio (false ), cin.tie (nullptr ); int n, k, ans = 0 ; cin >> n >> k; for (int i = 1 ; i <= n; i++) { int x, y; char op; cin >> x >> y >> op; if (op == 'W' ) x += k; sum[x % (2 * k) + 1 ][y % (2 * k) + 1 ]++; } for (int i = 1 ; i <= 2 * k; i++) for (int j = 1 ; j <= 2 * k; j++) sum[i][j] += sum[i - 1 ][j] + sum[i][j - 1 ] - sum[i - 1 ][j - 1 ]; for (int i = 1 ; i <= k; i++) for (int j = 1 ; j <= k; j++) { int tmp = calc (1 , 1 , i, j) + calc (i + 1 , j + 1 , i + k, j + k) + calc (i + k + 1 , j + k + 1 , 2 * k, 2 * k) + calc (i + k + 1 , 1 , 2 * k, j) + calc (1 , j + k + 1 , i, 2 * k); ans = max (ans, max (tmp, n - tmp)); } cout << ans; return 0 ; }