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

Codeforces Round 839 (Div. 3)

时间:2023-12-18 15:11:06浏览次数:27  
标签:std int 839 Codeforces -- solve using Div include

Codeforces Round 839 (Div. 3)

image-20231212191352702

A. A+B?

跳过太水了、、、、、

#include <bits/stdc++.h>

using namespace std;

int main()
{
    int t;
    cin >> t;
    while (t--) {
        int a,b;
        scanf("%d+%d",&a,&b);
        cout << a+b << endl;
    }
}

B. Matrix Rotation

题意:给定两行每行两个数,满足一下条件

  • 在每一行中,第一个元素小于第二个元素;
  • 在每一列中,第一个元素都小于第二个元素

思路:很明显只需要最大数和最小数处于对角线就行

#include <bits/stdc++.h>

using namespace std;

void solve() {
    int a[3][3];
    int mi = 0x3f3f3f3f, x1 = 0, y1 = 0;
    int ma = 0, x2 = 0, y2 = 0;
    for (int i = 1; i <= 2; i++) {
        for (int j = 1; j <= 2; j++) {
            cin >> a[i][j];
            if (a[i][j] < mi) {
                mi = a[i][j];
                x1 = i;
                y1 = j;
            }
            if (a[i][j] > ma) {
                ma = a[i][j];
                x2 = i;
                y2 = j;
            }
        }
    }
    if (x2 + x1 == 3 && y1 + y2 == 3) {
        cout << "YES\n";
    } else {
        cout << "NO\n";
    }
}

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

C. Different Differences

题意:定义一个数组其元素是从1-n中的一个
$$
我们定义其特征为a_i-a_{i-1}
$$
求具有最大特征的原数列

思路:很明显这个数据是单增的,那么最大也就是n,每个特征也是单增的,什么时候最大呢,假设后面的特征都是1,那么第k个数的大小就是:a[i-1]+cnt+k+i,如果他大于n那么a[i]-a[i-1]=1,后面也类似

#include <bits/stdc++.h>

using namespace std;

void solve() {
    int n, k;
    cin >> k >> n;
    int cnt = 1;
    vector<int> a(k + 1);
    a[1] = 1;
    for (int i = 2; i <= k; i++) {
        a[i] = a[i - 1] + (++cnt);
        if (a[i - 1] + cnt + k - i > n) {
            for (; i <= k; i++) {
                a[i] = a[i - 1] + 1;
            }
            break;
        }
    }
    for (int i = 1; i <= k; i++) {
        cout << a[i] << " ";
    }
    cout << "\n";
}

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

D. Absolute Sorting

题意:操作:找到一个数x将该数组中的数全部变成abs(a[i]-x);目标:数组单增

思路:1.什么情况要减去x? a[i+1]<a[i]

​ 2.x怎么取值? (a[i]+a[i+1]+1)/2(最开始没想到+1,后面想a[i+1]>a[i],所以x应该大一点点,减的更多负的绝对值更大)

​ 3.什么时候没有这样的值? 找到x之后变化数组在此来看(之前想的是如果前面的有比后面需要转换的数还小的数就不行)(感谢样例!!!)

#include <bits/stdc++.h>

using namespace std;

void solve() {
    int n;
    cin >> n;
    vector<int> a(n + 2);
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    int ma = 0;
    for (int i = 2; i <= n; i++) {
        if (a[i] < a[i - 1]) {
            ma = max(ma, (a[i] + a[i - 1] + 1) / 2);
        }
    }
    for (int i = 1; i <= n; i++)
        a[i] = abs(a[i] - ma);
    for (int i = 2; i <= n; i++)
        if (a[i] < a[i - 1]) {
            cout << "-1" << endl;
            return;
        }
    cout << ma << endl;
}

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

E. Permutation Game

题意:给你一个排列,这个排列可以染色,若他未被染色则位置不能动,可进行的操作:

1.将一个字染色

2.将染色之后的数重新排列

3.跳过这一轮

判断:如果最后数列为升序,那么第一个玩家胜利,否则就是第二个玩家胜利

思路:这道题给的是排列!!!,太爱啦!!!,最开始没注意我还觉得是最长上升子序列模型+博弈论(我还觉得这个3操作会让这题变得很麻烦,准备再找下题干信息然后开始放弃)。那么只需要看1赢需要变那些,2赢需要变那些(都要重新排序我就直接略过那一次了)。1不需要动的是a[i]==i,2不需要动的数为a[i]=n-i+1。

#include <bits/stdc++.h>

using namespace std;

void solve() {
    int n;
    cin >> n;
    vector<int> a(n + 1);
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    int x = 0, y = 0, z = 0;
    for (int i = 1; i <= n; i++) {
        if (a[i] == i) x++;
        else if (a[i] == (n - i + 1)) y++;
        else z++;
    }
    if (y + z <= x) {
        cout << "First\n";
    } else if (x + z < y) {
        cout << "Second\n";
    } else {
        cout << "Tie\n";
    }
}

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

标签:std,int,839,Codeforces,--,solve,using,Div,include
From: https://www.cnblogs.com/bbbbear/p/17911287.html

相关文章

  • Educational Codeforces Round 131 (Rated for Div. 2)
    基本情况AB秒了。C知道是二分答案,check死活写不出来。C.ScheduleManagementProblem-C-Codeforces错误分析这题比较绕,搞了一个对应关系,大脑转不过来。写check的时候完全想不出合理的思路。很明显的要用桶来计数,但是怎么用不知道了。看了题解后发现,check不能遍历任......
  • Educational Codeforces Round 159 (Rated for Div. 2)
    EducationalCodeforcesRound159(RatedforDiv.2)A-BinaryImbalance解题思路:有一对\((0,1)\),那么\(0\)就能无限增长。代码:#include<bits/stdc++.h>usingnamespacestd;typedeflonglongll;constintN=2e5+10;typedefpair<ll,ll>pii;constllm......
  • Codeforces Round 915 (Div. 2)
    基本情况A题还没进入状态,卡了快10分钟。B题一开始想复杂了,以为是树的直径,后面推出来发现针对叶子数目讨论就行了,正确思路出来太慢了(一个半小时)。C题留了半个多小时,随便口胡了一个LIS思路,但是判断无解没思路。C.LargestSubsequenceProblem-C-Codeforces首先我们把字......
  • Educational Codeforces Round 134 (Rated for Div. 2)
    基本情况AB秒了。C搞了一个错的二分答案,虽然过样例了。C.Min-MaxArrayTransformation错误分析没有进一步推导性质,而是觉得数据单调递增估计是二分,然后就无脑写,实际上check的正确性没有保证。boolcheck(intind,intnow){ if(ind==now)returntrue; if(b[ind]......
  • Codeforces Round 867 (Div. 3)
    CodeforcesRound867(Div.3)A:ABCD(E差一点点,最后把那种特殊情况想出来然后没写上去就结束了)A.TubeTubeFeed题意:给两个数组分别是时间和价值,要价值最大但是只能选一个思路:最开始以为是01背包,结果只选一个,一个一个枚举就行#include<bits/stdc++.h>usingnamespace......
  • Codeforces Round 855 (Div. 3)
    CodeforcesRound855(Div.3)A.IsItaCat?题意:要求:字符串必须以只包含字母"m"或"M"的非空序列开始必须紧跟由'e'或'E'字符组成的非空序列必须紧接着仅由字符'o'或'O'组成的非空序列必须紧接着是仅由字符'w'或'W'组成的非空序列思路:一个一个来(WA了三发注意这几......
  • Codeforces Round 913 (Div. 3)
    CodeforcesRound913(Div.3)A:ABCA.Rook简单题,就两个循环搞定(直接上码)#include<bits/stdc++.h>usingnamespacestd;voidsolve(){chara;intb;cin>>a>>b;for(inti=1;i<=8;i++){if(i!=b){......
  • Codeforces Round 863 (Div. 3)
    CodeforcesRound863(Div.3)A.InsertDigit题意:插入一个字母使得这个数字最大化思路:只要从前往后便利就行#include<iostream>usingnamespacestd;voidsolve(){intn,k;cin>>n>>k;boolx=true,y=false;for(inti=0;i<n;i++){......
  • Codeforces Round 913 (Div. 3)
    CF1907总结A.Rook题面翻译给出车在国际象棋棋盘中的位置,输出其可到达的坐标(不必在意顺序)。车可以横着或竖着走任意格数。分析题意明了,输出车所在行和列所有格子的序号(除车所在位置外)。code#include<bits/stdc++.h>usingnamespacestd;intt;voidsolve(){ string......
  • Codeforces Round 891 (Div3)
    CodeforcesRound891(Div.3)A.ArrayColoring这个我vp的时候写复杂了,想不到答案的思路这么清晰,将两部分分别看,将偶数加进去其奇偶性不变,只有奇数加进去才会改变奇偶性,so只有改变偶数次奇偶性才能使其奇偶性相同,所以cnt%2==0.#include<bits/stdc++.h>usingnamespacestd;......