A. Floor Number

https://codeforces.com/contest/1426/problem/A

Codeforces Round #674 (Div. 3) (A - F题题解) - 图1

题意:

一个楼房房间号由 Codeforces Round #674 (Div. 3) (A - F题题解) - 图2 递增,一楼仅2个房间。给定一位用户的房间号和 Codeforces Round #674 (Div. 3) (A - F题题解) - 图3楼以上每层的房间数Codeforces Round #674 (Div. 3) (A - F题题解) - 图4

求出用户所在楼层

思路:

很简单,理解题意即可。

如果 Codeforces Round #674 (Div. 3) (A - F题题解) - 图5 ,则答案为1。否则,您可以“删除”第一层,然后答案为 Codeforces Round #674 (Div. 3) (A - F题题解) - 图6

  1. #python
  2. for i in range(int(input())):
  3. n, x = map(int, input().split())
  4. print(1 if n <= 2 else (n - 3) // x + 2)
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. int main() {
  5. //freopen("in.txt", "r", stdin);
  6. ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  7. int _; cin >> _; while (_--) {
  8. ll n, x;
  9. cin >> n >> x;
  10. if (n <= 2)cout << 1 << endl;
  11. else cout << (n - 3) / x + 2 << endl;
  12. }
  13. }

B. Symmetric Matrix

https://codeforces.com/contest/1426/problem/B

题目有点长,大家点击链接看原题 或者 题意↓

题意:

给定 n 种 2 x 2大小的方块,问是否能通过这些方块组成 m x m的矩形(需要 Codeforces Round #674 (Div. 3) (A - F题题解) - 图7)

思路:

首先,如果m为奇数,则出于显而易见的原因,答案为“否”。 否则,我们会注意到图块的左上角和右下角值无关紧要(因为我们可以对称放置图块)。 因此,我们只需要检查是否有一些图块的右上值等于其左下值(因为这是我们获得主对角线对称性的方式)。

  1. #python
  2. for i in range(int(input())):
  3. n, m = map(int, input().split())
  4. a = []
  5. for i in range(n):
  6. a.append([[int(x) for x in input().split()] for i in range(2)])
  7. ok = False
  8. for i in range(n):
  9. ok |= a[i][0][1] == a[i][1][0]
  10. ok &= m % 2 == 0
  11. print("YES" if ok else "NO")
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. void solve() {
  5. ll n, m;
  6. cin >> n >> m;
  7. ll a, b, c, d;
  8. bool f1 = 0, f2 = 0;
  9. for (int i = 1; i <= n; ++i) {
  10. cin >> a >> b >> c >> d;
  11. if (!f2 && b == c)f2 = 1;
  12. }
  13. if (m % 2 == 0)f1 = 1;
  14. if (f1 && f2)cout << "YES" << endl;
  15. else cout << "NO" << endl;
  16. }
  17. int main() {
  18. //freopen("in.txt", "r", stdin);
  19. ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  20. int _; cin >> _; while (_--)solve();
  21. }

C. Increase and Copy

https://codeforces.com/contest/1426/problem/CCodeforces Round #674 (Div. 3) (A - F题题解) - 图8

题意:

思路:

直观地说,我们首先需要进行所有增量操作,然后才需要复制数字(因为否则我们可以交换移动顺序,并且总和不会减少)。 您可能会注意到答案不超过 Codeforces Round #674 (Div. 3) (A - F题题解) - 图9,所以我们可以从1迭代到⌊Codeforces Round #674 (Div. 3) (A - F题题解) - 图10⌋,然后确定要复制的数字。 设为x。 那么我们需要x-1个移动来获得它,还需要⌈Codeforces Round #674 (Div. 3) (A - F题题解) - 图11⌉个移动来获得足够数量的副本。 因此,我们可以用此举数来更新答案。
时间复杂度:每个测试用例为Codeforces Round #674 (Div. 3) (A - F题题解) - 图12
实际上,所需的数字总是非常接近⌊Codeforces Round #674 (Div. 3) (A - F题题解) - 图13⌋,因此只要尝试在[⌊Codeforces Round #674 (Div. 3) (A - F题题解) - 图14⌋-5; ⌊Codeforces Round #674 (Div. 3) (A - F题题解) - 图15⌋ + 5]范围内进行一些选择就足够了。 回答。 这是 Codeforces Round #674 (Div. 3) (A - F题题解) - 图16解决方案。

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main() {
  4. //freopen("in.txt", "r", stdin);
  5. ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  6. int t;
  7. cin >> t;
  8. while (t--) {
  9. int n;
  10. cin >> n;
  11. int ans = 1e9;
  12. for (int x = 1; x * x <= n; ++x) {
  13. ans = min(ans, x - 1 + ((n - x) + x - 1) / x);
  14. }
  15. cout << ans << endl;
  16. }
  17. }

D. Non-zero Segments

https://codeforces.com/contest/1426/problem/D

Codeforces Round #674 (Div. 3) (A - F题题解) - 图17

从开始遍历,利用sum去统计前面一段的值。

如果已经出现过,说明会导致有区间和为0的情况出现,ans++并且map clear 重新计数 sum从当前开始.

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. int main() {
  5. //freopen("in.txt", "r", stdin);
  6. ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  7. int n; cin >> n;
  8. map<ll, ll>m;
  9. ll ans = 0, sum = 0, x;
  10. m[0]++;
  11. for (int i = 0; i < n; ++i) {
  12. cin >> x;
  13. sum += x;
  14. if (m[sum] > 0) {
  15. ans++;
  16. sum = x;
  17. m.clear();
  18. m[0]++;
  19. }
  20. m[sum]++;
  21. }
  22. cout << ans;
  23. }

E. Rock, Paper, Scissors

https://codeforces.com/contest/1426/problem/E

Alice 和 Bob这次开始玩猜拳了,给定他们玩的次数n,和石头剪刀布出现的次数,求Alice能赢的最多次数和最少次数。

思路:

赢最多不用说吧?

赢最少, 无非是 拳头被拳头和包吃了, 剪刀被剪刀和石头吃了, 包被拳头和包吃了

抵消完后, 要么你剩下拳头/剪刀/包, 对手剩下剪刀/包/拳头, 这就是你最少赢的

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. ll q_max(ll x, ll y, ll z, ll h) {
  5. x = x > y ? x : y;
  6. x = x > z ? x : z;
  7. x = x > h ? x : h;
  8. return x;
  9. }
  10. int main() {
  11. //freopen("in.txt", "r", stdin);
  12. ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  13. ll n, a, b, c, x, y, z;
  14. cin >> n;
  15. cin >> a >> b >> c >> x >> y >> z;
  16. cout << q_max(0, a - x - z, b - x - y, c - y - z ) << " " << min(a, y) + min(b, z) + min(c, x);
  17. }

F. Number of Subsequences

没做出来

先贴一下dalao的代码留做学习

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. const int mod = 1e9 + 7;
  4. typedef ll ll;
  5. int main() {
  6. int n; cin >> n;
  7. string ss; cin >> ss;
  8. ll x = 0;
  9. ll ans = 0;
  10. ll temp = 0;
  11. ll num = 1;
  12. for (int i = 0; i < n; i++) {
  13. if (ss[i] == 'a') x += num;
  14. else if (ss[i] == 'b') temp += x;
  15. else if (ss[i] == 'c') ans += temp;
  16. else {
  17. ans = ans * 3 + temp;
  18. temp = temp * 3 + x;
  19. x = x * 3 + num;
  20. num *= 3;
  21. }
  22. num %= mod;
  23. x %= mod; temp %= mod; ans %= mod;
  24. }
  25. cout << ans << endl;
  26. }

学习隔壁 洛绫璃dalao 的写法:

利用模拟思想:

题目问我们能组成 abc 的可能性,需要在3^k的情况取模

先把可能的情况标出来以后再处理

  1. 1~~a
  2. 2~~?
  3. 3~~ab
  4. 4~~a?
  5. 5~~?b
  6. 6~~??
  7. 7~~abc
  8. 8~~ab?
  9. 9~~a?c
  10. 10~~?bc
  11. 11~~a??
  12. 12~~?b?
  13. 13~~??c
  14. 14~~???
  1. #include <bits/stdc++.h>
  2. #define rep(i,a,b) for(int i=(a);i<=(b);++i)
  3. #define IOS ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)
  4. using namespace std;
  5. typedef long long ll;
  6. const int N = 2e5 + 5, mod = 1e9 + 7;
  7. int n, m, _, k;
  8. char s[N];
  9. ll a[20], ans = 0;
  10. int qpow(ll a, ll b) {//快速幂
  11. ll ans = 1; a %= mod;
  12. for (; b; a = a * a % mod, b >>= 1)
  13. if (b & 1) ans = ans * a % mod;
  14. return ans;
  15. }
  16. int main() {
  17. IOS; cin >> n;
  18. cin >> s + 1;
  19. rep(i, 1, n)
  20. if (s[i] == 'a') ++a[1];
  21. else if (s[i] == 'b') {
  22. a[3] += a[1];
  23. a[5] += a[2];
  24. }
  25. else if (s[i] == 'c') {
  26. a[7] += a[3];
  27. a[9] += a[4];
  28. a[10] += a[5];
  29. a[13] += a[6];
  30. }
  31. else {
  32. a[14] += a[6];
  33. a[12] += a[5];
  34. a[11] += a[4];
  35. a[8] += a[3];
  36. a[6] += a[2];
  37. a[4] += a[1];
  38. ++a[2];
  39. }
  40. //如果存在这种可能性,利用相应组合计算
  41. if (a[7]) ans = a[7] % mod * qpow(3, a[2]) % mod;
  42. if (a[8]) ans = (ans + a[8] % mod * qpow(3, a[2] - 1) % mod) % mod;
  43. if (a[9]) ans = (ans + a[9] % mod * qpow(3, a[2] - 1) % mod) % mod;
  44. if (a[10]) ans = (ans + a[10] % mod * qpow(3, a[2] - 1) % mod) % mod;
  45. if (a[11]) ans = (ans + a[11] % mod * qpow(3, a[2] - 2) % mod) % mod;
  46. if (a[12]) ans = (ans + a[12] % mod * qpow(3, a[2] - 2) % mod) % mod;
  47. if (a[13]) ans = (ans + a[13] % mod * qpow(3, a[2] - 2) % mod) % mod;
  48. if (a[14]) ans = (ans + a[14] % mod * qpow(3, a[2] - 3) % mod) % mod;
  49. cout << ans;
  50. return 0;
  51. }