首页 > 其他分享 >Codeforces Round #839 (Div. 3) A-E

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

时间:2023-01-08 11:34:34浏览次数:79  
标签:cout int 839 Codeforces cin -- solve Div check

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 ();
}

//没考虑公共部分

标签:cout,int,839,Codeforces,cin,--,solve,Div,check
From: https://www.cnblogs.com/CTing/p/17034286.html

相关文章

  • CodeForces - 1760F Quests
    CodeForces-1760FQuests题解:二分答案首先我们来分析一题目,如果说K越大,我们在d天里很有可能得不到C个硬币,所以K的最大值一定在合法答案和不合法答案的临界点,并且这些......
  • Codeforces - 1656E - Equal Tree Sums(构造 + 树论 + 图论 + 搜索、结论题、*2200)
    1656E-EqualTreeSums(⇔源地址)目录1656E-EqualTreeSums(⇔源地址)tag题意思路AC代码错误次数:0tag⇔*2200、⇔构造、⇔树论、⇔图论、⇔搜......
  • CF#842-div2-C
    题意给定一个序列A,让你构造两个序列BC满足:\(max(B[i],C[i])=A[i]\)能构造输出YES然后输出两个构造序列BC,不能构造输出NO题解显然,我想到如果A序列中出现三个及以......
  • bug|记录某次页面div使用v-html标签渲染图片等内容的过程
    前言记录某次页面div使用v-html标签渲染图片等内容的过程一、结论:get请求但被设置Sec-Fetch-*请求头的图片无法展示。二、原因:1.本项目中的img标签发起get请求,目标链......
  • 1.4 SMU Winter 2023 Round #1 (Div.2)
    [语言月赛202212]不可以,总司令思路:比较大小 if(x>y)cout<<"NO";elseif(x<y)cout<<"YES";elsecout<<"equalprobability"; [语言月赛202212]计算......
  • 1.7 vp Codeforces Round #839 (Div. 3)
    A-A+B?题意:给出两个0~9的数字和一个加号。要求输出数字相加的和思路:用字符串输入,第一位和第三位相加减去两个字符0即为数字和。voidsolve(){ strings; cin>>s;......
  • 使用div+css实现表格布局
    DIV+CSS是WEB设计标准,它是一种网页的布局方法。与传统中通过表格(table)布局定位的方式不同,它可以实现网页页面内容与表现相分离。提起​​DIV+CSS​​​组合,还要从XHTML说起......
  • [ABC254Ex] Multiply or Divide by 2 题解
    [ABC254Ex]MultiplyorDivideby2Solution目录[ABC254Ex]MultiplyorDivideby2Solution更好的阅读体验戳此进入题面SolutionCodeUPD更好的阅读体验戳此进入题......
  • 1.6 SMU Winter 2023 Round #2 (Div.2)
    SMUWinter2023Round#2(Div.2)1760A-MediumNumber思路:排列后,输出第二大的数intmain(){intt,a[5];cin>>t;while(t--){for(inti=0;i......
  • 2023/1/6/冬令营codeforces比赛复盘
    #I.TheHumanoid(人形生物)##[原题传送通道](https://codeforces.com/group/L9GOcnr1dm/contest/418722/problem/I)##思路:1.将各个宇航员a[i]从小到大sort排序,减小Huma......