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

    Educational Codeforces Round 94 (A - D题题解) - 图1

    Example

    input

    1. 4
    2. 1
    3. 1
    4. 3
    5. 00000
    6. 4
    7. 1110000
    8. 2
    9. 101

    output

    1. 1
    2. 000
    3. 1010
    4. 00

    思路:先贴下代码,有事要去医院,等会补上思路。

    AC代码:

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

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

    Educational Codeforces Round 94 (A - D题题解) - 图2

    Example

    input

    1. 3
    2. 33 27
    3. 6 10
    4. 5 6
    5. 100 200
    6. 10 10
    7. 5 5
    8. 1 19
    9. 1 3
    10. 19 5

    output

    1. 11
    2. 20
    3. 3

    思路:

    AC代码:

    1. #include<bits/stdc++.h>
    2. #define ms(a,b) memset(a,b,sizeof a)
    3. using namespace std;
    4. const int N = 1e5 + 100;
    5. typedef long long ll;
    6. ll n, m, a[N];
    7. void solve() {
    8. int p, f;
    9. cin >> p >> f;
    10. int cnts, cntw, s, w;
    11. cin >> cnts >> cntw >> s >> w;
    12. if (s > w) {
    13. swap(s, w);
    14. swap(cnts, cntw);
    15. }
    16. int maxi = 0;
    17. for (int i = 0; i <= min(cnts, p / s); i++) {
    18. int a = min(cntw, (p - i * s) / w);
    19. int b = min(cnts - i, f / s);
    20. int c = min(cntw - a, (f - b * s) / w);
    21. maxi = max(maxi, a + b + c + i);
    22. }
    23. cout << maxi << '\n';
    24. }
    25. int main() {
    26. //freopen("in.txt", "r", stdin);
    27. ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    28. int t; cin >> t;
    29. while (t--)solve();
    30. }

    https://codeforces.com/contest/1400/problem/C

    Educational Codeforces Round 94 (A - D题题解) - 图3

    Example

    input

    1. 3
    2. 101110
    3. 2
    4. 01
    5. 1
    6. 110
    7. 1

    output

    1. 111011
    2. 10
    3. -1

    思路:

    AC代码:

    1. #include<bits/stdc++.h>
    2. #define ms(a,b) memset(a,b,sizeof a)
    3. using namespace std;
    4. const int N = 1e5 + 100;
    5. typedef long long ll;
    6. ll n, m, a[N];
    7. void solve() {
    8. ll x; string s, ss = "";
    9. cin >> s >> x;
    10. int n = s.size();
    11. for (int i = 0; i < n; ++i) ss += '1';
    12. for (int i = 0; i < n; ++i) {
    13. if (s[i] == '0' && i + x < n)ss[i + x] = '0';
    14. if (s[i] == '0' && i - x >= 0)ss[i - x] = '0';
    15. }
    16. bool flag = true;
    17. for (int i = 0; i < n; ++i) {
    18. if (s[i] == '1') {
    19. bool ok = false;
    20. if (i + x < n && ss[i + x] == '1') ok = true;
    21. if (i - x >= 0 && ss[i - x] == '1') ok = true;
    22. if (!ok) flag = false;
    23. }
    24. }
    25. if (!flag)cout << -1 << endl;
    26. else cout << ss << endl;
    27. }
    28. int main() {
    29. //freopen("in.txt", "r", stdin);
    30. ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    31. int t; cin >> t;
    32. while (t--)solve();
    33. }

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

    Educational Codeforces Round 94 (A - D题题解) - 图4

    Example

    input

    1. 2
    2. 5
    3. 2 2 2 2 2
    4. 6
    5. 1 3 3 1 2 3

    output

    1. 5
    2. 2

    思路:

    AC代码: 使用map,900+ms

    1. #include<bits/stdc++.h>
    2. #define ms(a,b) memset(a,b,sizeof a)
    3. using namespace std;
    4. const int N = 1e5 + 100;
    5. typedef long long ll;
    6. ll a[N];
    7. map<int, int>m1, m2;
    8. void solve() {
    9. m1.clear();
    10. int n; cin >> n;
    11. for (int i = 0; i < n; ++i)cin >> a[i];
    12. ll ans = 0;
    13. for (int i = 0; i < n; ++i) {
    14. m2.clear();
    15. for (int j = n - 1; j > i; --j)
    16. ans += m1[a[j]] * m2[a[i]], ++m2[a[j]];
    17. ++m1[a[i]];
    18. }
    19. cout << ans << endl;
    20. }
    21. int main() {
    22. //freopen("in.txt", "r", stdin);
    23. ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    24. int t; cin >> t;
    25. while (t--)solve();
    26. }