Codeforces Round #839 (Div. 3) A-E

Codeforces Round #839 (Div. 3) A-E

https://codeforces.com/contest/1772
之前打的一场忘记记录了,题也没补,今天想起来E博弈没过补一下,FG不想看了好长qwq
做太久已经忘了,索性不写做法了( ̄_, ̄ )

A. A+B?

#include <bits/stdc++.h>

using namespace std;

void solve () {
    string s;
    cin >> s;
    int ans = 0;
    ans += s[0] - '0' + s[2] - '0';
    cout << ans << endl;
}

int main () {
    int t;
    cin >> t;
    while (t --)    solve ();
}

B. Matrix Rotation

#include <bits/stdc++.h>

using namespace std;

bool check (int a, int b, int c, int d) {
    if (a < b && a < c && c < d && b < d)   return true;
    return false;
}

void solve () {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if (check (a, b, c, d) || check (c, a, d, b) || check (d, c, b, a) || check (b, d, a, c))   puts ("YES");
    else    puts ("NO");
}

int main () {
    int t;
    cin >> t;
    while (t --)    solve ();
}

C. Different Differences

#include <bits/stdc++.h>

using namespace std;
const int N = 45;
int a[N];

void solve () {
    int n, m;
    cin >> n >> m;
    a[0] = 1;
    for (int i = 1, dx = 0; i <= n; i++, dx ++)    a[i] = a[i-1] + dx;
    int pos = upper_bound (a + 1, a + n + 1, m) - a;
    //cout << pos << endl;
    int res = n - pos + 1;
    //cout << res << endl;
    if (res) { //改
        int i, j;
        for (i = n, j = 0; i >= pos; i--, j++)  a[i] = m - j;
        //cout << i << ' ' << j << endl;
        while (i >= 1 && a[i] >= a[i+1])    a[i] = a[i+1] - 1, i --;
    }
    for (int i = 1; i <= n; i++)    cout << a[i] << ' ';    cout << endl;
}

int main () {
    int t;
    cin >> t;
    while (t --)    solve ();
}
//k个严格增数,范围1-n
//两两差值京可能不同

D. Absolute Sorting

#include <bits/stdc++.h>

using namespace std;
const int N = 2e5 + 5, inf = 1e9;
int a[N], n;

bool check (int x) {
    int lst = abs (a[1] - x);
    for (int i = 2; i <= n; i++) {
        int cur = abs (a[i] - x);
        if (lst > cur)  return false;
        lst = cur;
    }
    return true;
}

void solve () {
    cin >> n;
    for (int i = 1; i <= n; i++)    cin >> a[i];
    //for (int i = 2; i <= n; i++)    cout << a[i] - a[i-1] << ' ';cout << endl;
    int minn = inf, maxn = 0;
    for (int i = 1; i < n; i++) {
        if (a[i] == a[i+1]) {
            //cout << "any\n";
            continue;
        }
        int val = (a[i] + a[i+1]) / 2;
        if (a[i] < a[i+1]) {
            //cout << "<=";
            minn = min (minn, val);
            //v1.insert (val);
        }
        else {
            //cout << ">="; 
            maxn = max (maxn, val);
            //v2.insert (val);
        }
        //cout << val << endl; 
    }
    //cout << endl;
    //cout << minn << ' ' << maxn << endl;
    if (minn == inf) {
        for (int i = maxn; ; i++) {
            if (check (i)) {
                cout << i << endl;
                break;
            }
        }
    }
    else if (maxn == 0) {
        for (int i = minn; i >= 0; i--) {
            if (check (i)) {
                cout << i << endl;
                break;
            }
        }
    }
    else {
        if (minn < maxn)    cout << "-1\n";
        else {
            for (int i = maxn; i <= minn; i++) {
                if (check (i)) {
                    cout << i << endl;
                    return ;
                }
            }
            cout << "-1\n";
        }
    }
}

int main () {
    int t;
    cin >> t;
    while (t --)    solve ();
}

//ai

E. Permutation Game

没考虑公共部分,看代码就懂了

#include <bits/stdc++.h>

using namespace std;
const int N = 5e5 + 5, inf = 1e9;
int a[N], n;

void solve () {
    cin >> n;
    for (int i = 1; i <= n; i++)    cin >> a[i];
    int sum1 = 0, sum2 = 0, sum3 = 0;
    for (int i = 1; i <= n; i++) {
        if (a[i] == i)  sum1 ++; //1不变的
        else if (a[i] == n - i + 1)  sum2 ++; //2不变的
        else    sum3 ++; //公共
    }
    //cout << sum1 << ' ' << sum2 << endl;
    if (sum1 >= sum2 + sum3)    cout << "First\n"; //先手多一票
    else if (sum2 > sum1 + sum3)   cout << "Second\n";
    else    cout << "Tie\n";
}

int main () {
    int t;
    cin >> t;
    while (t --)    solve ();
}

//没考虑公共部分
posted @ 2023-01-08 11:22  Sakana~  阅读(16)  评论(0编辑  收藏  举报