完整代码:https://github.com/abmcar/ACM/tree/master/OpenjudgeNow/Codeforces/Educational%20Codeforces%20Round%20119%20(Rated%20for%20Div.%202)

A. Equal or Not Equal

在这里插入图片描述
题目大意:给你一个一堆数,并知道他们当中某些数和相邻的数相同,问可不可能围成一个圈
思路:一个看上去并不简单的A题,但实际上照着模拟即可
代码:

void work()
{
    // cin >> n;
    string oriString;
    cin >> oriString;
    n = oriString.size();
    vector<int> nums(n + 1, 0);
    nums[0] = 1;
    bool fir = true;
    for (int i = 0; i < oriString.size(); i++)
    {
        if (oriString[i] == 'E')
            nums[i + 1] = nums[i];
        else
        {
            if (fir)
            {
                fir = false;
                nums[i + 1] = !nums[i];
            }
            else
                nums[i + 1] = nums[0];
        }
    }
    if (nums[n] == nums[0])
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}

B. Triangles on a Rectangle

在这里插入图片描述
题目大意:给你一个矩形,有一些点在矩形的边上,问其中三个点组成的三角形的最大面积(其中2个点在一个边上)
思路:很容易能看出这个三角形的面积就是同一边两点距离和临边距离的乘积/2,只需要判断每个边上最长的距离尝试组三角形即可
代码:

void work()
{
    vector<int> V;
    int w, h, k;
    int ans = 0;
    cin >> w >> h;
    cin >> k;
    V.resize(k + 1);
    for (int i = 1; i <= k; i++)
        cin >> V[i];
    ans = max(ans, (V[k] - V[1]) * h);
    cin >> k;
    V.resize(k + 1);
    for (int i = 1; i <= k; i++)
        cin >> V[i];
    ans = max(ans, (V[k] - V[1]) * h);

    cin >> k;
    V.resize(k + 1);
    for (int i = 1; i <= k; i++)
        cin >> V[i];
    ans = max(ans, (V[k] - V[1]) * w);
    cin >> k;
    V.resize(k + 1);
    for (int i = 1; i <= k; i++)
        cin >> V[i];
    ans = max(ans, (V[k] - V[1]) * w);

    cout << ans << endl;
}

C. BA-String

在这里插入图片描述
题目大意:给你一个由a和*组成的字符串,其中一个*可以替换成0-k个b,问替换完字典序第x小的字符串
思路:把连续的*看成某一位,按照进制转换进位的思想一步一步更改x
代码:

void work()
{
    string oriS;
    cin >> n >> k >> x;
    cin >> oriS;
    if (k == 0)
    {
        for (auto it : oriS)
            if (it != '*')
                cout << it;
        cout << endl;
        return;
    }
    x--;
    string ansS = "";
    reverse(oriS.begin(), oriS.end());
    int cnt = 0;
    int nowValue = 1;
    for (auto it : oriS)
    {
        if (it != '*')
        {
            if (cnt != 0)
            {
                int nowLen = k * cnt;
                int nowNum = x % (nowLen + 1);
                // x = x - nowNum * nowValue;
                x = x / (nowLen + 1);
                for (int i = 1; i <= nowNum; i++)
                    ansS += "b";
                cnt = 0;
            }
            ansS += it;
        }
        else
            cnt++;
    }
    int nowLen = k * cnt;
    int nowNum = min(nowLen, x / nowValue);
    x = x - nowNum * nowValue;
    nowValue *= nowLen;
    for (int i = 1; i <= nowNum; i++)
        ansS += "b";
    reverse(ansS.begin(), ansS.end());
    cout << ansS << endl;
}

E. Replace the Numbers

在这里插入图片描述
题目大意:给你一串操作,1是把某个数放到末尾,2是把所有的x替换成y,问最终结果
思路:我们倒叙处理2操作来免除后效性,对于每一个操作2,我们用并查集的思路记录变更结果
代码:

void work()
{
    cin >> n;
    vector<int> V;
    vector<pair<int, int>> d[n + 1];
    for (int i = 1; i <= n; i++)
    {
        int opt, arg1, arg2;
        cin >> opt;
        if (opt == 1)
        {
            cin >> arg1;
            V.push_back(arg1);
        }
        else
        {
            cin >> arg1 >> arg2;
            if (V.size() == 0)
                continue;
            d[V.size() - 1].push_back({arg1, arg2});
        }
    }
    for (int i = 1; i <= Maxn; i++)
        father[i] = i;
    for (int i = V.size() - 1; i >= 0; i--)
    {
        for_each(d[i].rbegin(), d[i].rend(), [](auto it)
                 { father[it.first] = father[it.second]; });
        V[i] = father[V[i]];
    }
    for_each(V.begin(), V.end(), [](int it)
             { cout << it << " "; });
    cout << endl;
}

Q.E.D.