首页 > 其他 > 详细

Educational Codeforces Round 113 (Rated for Div. 2)

时间:2021-09-13 10:13:38      阅读:24      评论:0      收藏:0      [点我收藏+]

A. Balanced Substring

思路:

任何非空平衡字符串都包含至少一个字母"a"和至少一个字母"b"。这意味着在那个字符串的某个地方有一个"旁边"b。两个字符串"ab"和"ba"是平衡的。因此,任何平衡字符串都包含长度的平衡子串22.因此,解决方案是检查所有n-1对相邻字母对。如果存在一对不同的,打印它。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>

using namespace std;

const int N = 50010;

typedef pair<int, int>PII;
typedef long long LL;

int main()
{
    int T;
    cin >> T;
    while (T--)
    {
        int n;
        cin >> n;
        string s;
        cin >> s;
        bool flag = false;
        for (int i = 0; i < n - 1; i++)
            if (s[i] != s[i + 1])
            {
                cout << i + 1 <<   << i + 2 << endl;
                flag = true;
                break;
            }

        if (!flag) cout << -1 <<   << -1 << endl;
            
    }
    return 0;
}

B. Chess Tournament

思路:

首先对于要求1的人
我们让他全部平局,因为这样不会造成一个人赢一个人输的情况
如果赢了一个要求为1的人,那样就不满足了
所以,我们让要求1的人全部平局

对于要求2的人
我们让他赢一个人,显然他不能赢要求为1的人,只能赢要求为2的人了
那么我们找出所有要求为2的人
让他们互相赢

所以当要求为2人数小于等于2时,NO
大于2时,互相赢就好(一个环)

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>

using namespace std;

typedef pair<int, int>PII;
typedef long long LL;

int main()
{
    int T;
    cin >> T;
    while (T--)
    {
        int n;
        cin >> n;
        string s;
        cin >> s;
        vector<int>id;
        for (int i = 0; i < n; i++)
            if (s[i] == 2)
                id.push_back(i);
        
        int k = id.size();
        if (k == 1 || k == 2)
        {
            cout << "NO" << endl;
            continue;
        }

        vector<string> res(n, string(n, =));//把res容量设为n,其中所有的元素都是‘=‘
        for (int i = 0; i < n; i++) res[i][i] = X;//对角线都是X
        for (int i = 0; i < k; i++)
        {
            int x = id[i], y = id[(i + 1) % k];
            res[x][y] = +;
            res[y][x] = -;
        }

        cout << "YES" << endl;
        for (int i = 0; i < n; i++) cout << res[i] << endl;
    }
    return 0;
}

先这样吧。。。最近脑子真是不好使了。。。。

Educational Codeforces Round 113 (Rated for Div. 2)

原文:https://www.cnblogs.com/yctql/p/15259817.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!