1421A. XORwice

题目链接:Click Here

  1. // Author : RioTian
  2. // Time : 20/10/18
  3. #include <bits/stdc++.h>
  4. #define ms(a, b) memset(a, b, sizeof a)
  5. using namespace std;
  6. typedef long long ll;
  7. ll n, m, _;
  8. void solve() {
  9. cin >> n >> m;
  10. cout << (n ^ m) << endl;
  11. }
  12. int main() {
  13. // freopen("in.txt", "r", stdin);
  14. ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  15. cin >> _;
  16. while (_--) solve();
  17. }

1421B. Putting Bricks in the Wall

题目链接:Click Here

如果选择S的邻居为1,我们就可以F使为0的邻居,就没有办法从S到F,但这在最坏的情况下需要4个开关,这是不够的。 幸运的是,为了减少到2个开关,只需反过来考虑,使相邻S的正方形变为0,使相邻的正方形变为F 1。必须存在最多具有两个开关的两个正方形的解,并且您不会从S到F,因为被迫选择1(或0),并且无法通过与F相反的邻居。

  1. // Author : RioTian
  2. // Time : 20/10/18
  3. #include <bits/stdc++.h>
  4. #define ms(a, b) memset(a, b, sizeof a)
  5. using namespace std;
  6. typedef long long ll;
  7. ll n, m, _;
  8. char x[210][210];
  9. void solve() {
  10. cin >> n;
  11. for (int i = 1; i <= n; i++) cin >> x[i] + 1;
  12. int a = x[1][2] - '0', b = x[2][1] - '0', c = x[n][n - 1] - '0',
  13. d = x[n - 1][n] - '0';
  14. if (a == b && c == d && a != c)
  15. cout << 0 << endl;
  16. else if (a != b && c != d)
  17. cout << 2 << endl
  18. << 1 << " " << 2 << endl
  19. << (a == c ? n - 1 : n) << " " << (a == c ? n : n - 1) << endl;
  20. else if (a != b)
  21. cout << 1 << endl
  22. << (a == c ? 1 : 2) << ' ' << (a == c ? 2 : 1) << endl;
  23. else if (c != d)
  24. cout << 1 << endl
  25. << (a == c ? n : n - 1) << ' ' << (a == c ? n - 1 : n) << endl;
  26. else
  27. cout << 2 << endl << 1 << ' ' << 2 << endl << 2 << " " << 1 << endl;
  28. }
  29. int main() {
  30. // freopen("in.txt", "r", stdin);
  31. ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  32. cin >> _;
  33. while (_--) solve();
  34. }
  1. #python
  2. import sys
  3. input = sys.stdin.readline
  4. I = lambda : list(map(int,input().split()))
  5. t,=I()
  6. for _ in range(t):
  7. n,=I()
  8. l=[input().strip() for i in range(n)]
  9. an=[]
  10. le=[0,0,1,1,1];p=[1,1,0,0,0]
  11. rq=[l[0][1],l[1][0],l[1][1],l[2][0],l[0][2]]
  12. pos=[[1,2],[2,1],[2,2],[3,1],[1,3]]
  13. ct=cp=0;a1=[]
  14. for i in range(5):
  15. if le[i]!=int(rq[i]):
  16. ct+=1
  17. a1.append(pos[i])
  18. for i in range(5):
  19. if p[i]!=int(rq[i]):
  20. cp+=1
  21. an.append(pos[i])
  22. if ct<=cp:
  23. an=a1
  24. print(len(an))
  25. for i in an:
  26. print(*i)

1421C. Palindromifier

题目链接:Click Here

这道题写的挺懵的,一开始都没理解题意

被dalao提醒以后然后发现是构造题,根据题目说的两种方案:

对于任何字符串都可以先 $L ,i = 2 Codeforces Round #676 (Div. 2)  A - D个人题解(E题待补) - 图1R,i = 2 $ + Codeforces Round #676 (Div. 2)  A - D个人题解(E题待补) - 图2。一定能构造需所需的字符串

  1. // Author : RioTian
  2. // Time : 20/10/18
  3. #include <bits/stdc++.h>
  4. using namespace std;
  5. typedef long long ll;
  6. string s;
  7. int main() {
  8. // freopen("in.txt","r",stdin);
  9. ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  10. cin >> s;
  11. cout << "3\nL 2\nR 2\n";
  12. cout << "R " << 2 * s.size() - 1 << endl;
  13. }
  1. print('3\nL 2\nR 2\nR',len(input())*2-1)

1421D. Hexagons (补)

题目链接:Click Here

  1. // Author : RioTian
  2. // Time : 20/10/18
  3. #include <bits/stdc++.h>
  4. using namespace std;
  5. #define ll long long
  6. int inf = 1e9 + 7;
  7. ll x, y, c1, c2, c3, c4, c5, c6;
  8. ll check(ll ad) {
  9. ll ans = 0;
  10. if (ad > 0)
  11. ans += ad * c1;
  12. else
  13. ans += -ad * c4;
  14. if (x - ad > 0)
  15. ans += (x - ad) * c6;
  16. else
  17. ans += (ad - x) * c3;
  18. if (y - ad > 0)
  19. ans += (y - ad) * c2;
  20. else
  21. ans += (ad - y) * c5;
  22. return ans;
  23. }
  24. void solve() {
  25. cin >> x >> y >> c1 >> c2 >> c3 >> c4 >> c5 >> c6;
  26. ll l = -inf, r = inf;
  27. while (l < r) {
  28. ll mid = l + r >> 1;
  29. if (check(mid) < check(mid + 1))
  30. r = mid;
  31. else
  32. l = mid + 1;
  33. }
  34. cout << min({check(l), check(l + 1), check(l - 1)}) << '\n';
  35. }
  36. int main() {
  37. int t;
  38. cin >> t;
  39. while (t--) solve();
  40. }

1421E. Swedish Heroes (补)

题目链接:Click Here