其他分享
首页 > 其他分享> > Codeforces Round #753 (Div. 3)

Codeforces Round #753 (Div. 3)

作者:互联网

Codeforces Round #753 (Div. 3)

A. Linear Keyboard

思路分析:

代码

#include <bits/stdc++.h>
using namespace std;
map<char, int> mp;
int main()
{
        ios::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
        int t;
        cin >> t;
        while (t--)
        {
                string s;
                cin >> s;
                for (int i = 0; i < s.size(); i++)
                {
                        mp[s[i]] = i + 1;
                }
                string t;
                cin >> t;
                int ans = 0;
                for (int i = 1; i < t.size(); i++)
                {
                        ans += abs(mp[t[i]] - mp[t[i - 1]]);
                }
                cout << ans << endl;
        }
        return 0;
}

B. Odd Grasshopper

思路分析:

代码

#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
        ios::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
        int t;
        cin >> t;
        while (t--)
        {
                ll x, n;
                cin >> x >> n;
                if (n == 0)
                {
                        cout << x << endl;
                }
                else
                {
                        if (x % 2 == 0)
                        {
                                x--;
                                n--;
                                x = x + n / 4 * (-4);
                                if (n % 4 == 0)
                                {
                                        cout << x << endl;
                                }
                                else if (n % 4 == 1)
                                {
                                        x += (n + 1);
                                        cout << x << endl;
                                }
                                else if (n % 4 == 2)
                                {
                                        x += (2 * n + 1);
                                        cout << x << endl;
                                }
                                else if (n % 4 == 3)
                                {
                                        x += (n - 2);
                                        cout << x << endl;
                                }
                        }
                        else
                        {
                                x++;
                                n--;
                                x = x + n / 4 * 4;
                                if (n % 4 == 0)
                                {
                                        cout << x << endl;
                                }
                                else if (n % 4 == 1)
                                {
                                        x -= (n + 1);
                                        cout << x << endl;
                                }
                                else if (n % 4 == 2)
                                {
                                        x -= (2 * n + 1);
                                        cout << x << endl;
                                }
                                else if (n % 4 == 3)
                                {
                                        x -= (n - 2);
                                        cout << x << endl;
                                }
                        }
                }
        }
        return 0;
}

C. Minimum Extraction

思路分析:

代码

#include <bits/stdc++.h>
using namespace std;

const int maxn = 2e5 + 10;
int a[maxn];

int main()
{
        ios::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
        int t;
        cin >> t;
        while (t--)
        {
                int n;
                cin >> n;
                for (int i = 1; i <= n; i++)
                {
                        cin >> a[i];
                }
                sort(a + 1, a + 1 + n);
                int ans = -1000000001;
                for (int i = 1; i <= n; i++)
                {
                        ans = max(ans, a[i] - a[i - 1]);
                }
                cout << ans << endl;
        }
        return 0;
}

D. Blue-Red Permutation

思路分析:

代码

#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
struct node
{
        int val;
        char ch;
} a[maxn];

bool cmp(node a, node b)
{
        if (a.ch != b.ch)
                return a.ch < b.ch;
        return a.val < b.val;
}
int main()
{
        ios::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
        int t;
        cin >> t;
        while (t--)
        {
                int n;
                cin >> n;
                for (int i = 1; i <= n; i++)
                {
                        cin >> a[i].val;
                }
                for (int i = 1; i <= n; i++)
                {
                        cin >> a[i].ch;
                }
                sort(a + 1, a + 1 + n, cmp);
                bool flag = 1;
                int tmp = 1;
                for (int i = 1; i <= n; i++)
                {
                        if (a[i].val < tmp && a[i].ch == 'B')
                        {
                                flag = 0;
                                break;
                        }
                        else if (a[i].val > tmp && a[i].ch == 'R')
                        {
                                flag = 0;
                                break;
                        }
                        else
                        {
                                tmp++;
                        }
                }
                if (flag)
                {
                        cout << "YES" << endl;
                }
                else
                {
                        cout << "NO" << endl;
                }
        }
        return 0;
}

E. Robot on the Board 1

思路分析:

代码

#include <bits/stdc++.h>
using namespace std;

int main()
{
        ios::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
        int t;
        cin >> t;
        while (t--)
        {
                int n, m;
                cin >> n >> m;
                string s;
                cin >> s;
                pair<int, int> a;
                a = {1, 1};
                bool flag = 0;
                int l = 0, r = m + 1, u = 0, d = n + 1;
                int suml = 0, sumr = 0, sumu = 0, sumd = 0;
                for (int i = 0; i < s.size(); i++)
                {
                        if (s[i] == 'R')
                        {
                                sumr++;
                        }
                        else if (s[i] == 'L')
                        {
                                suml++;
                        }
                        else if (s[i] == 'U')
                        {
                                sumu++;
                        }
                        else if (s[i] == 'D')
                        {
                                sumd++;
                        }
                        l = max(l, suml - sumr);
                        r = min(r, m + 1 - (sumr - suml));
                        u = max(u, sumu - sumd);
                        d = min(d, n + 1 - (sumd - sumu));
                        if (l + 1 >= r || u + 1 >= d)
                        {
                                flag = 1;
                                cout << a.first << ' ' << a.second << endl;
                                break;
                        }
                        else
                        {
                                a = {u + 1, l + 1};
                        }
                }
                if (!flag)
                        cout << a.first << " " << a.second << endl;
        }
        return 0;
}

标签:753,ch,cout,int,Codeforces,cin,++,tie,Div
来源: https://www.cnblogs.com/csu-yuuki/p/15505573.html