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

Codeforces Round 834 (Div. 3)

时间:2023-12-18 15:12:30浏览次数:26  
标签:cout 834 int Codeforces -- while solve Div gcd

Codeforces Round 834 (Div. 3)

image-20231217162412324

A. Yes-Yes?

题意:就是Y后面跟e,e后面跟s,s后面跟Y

#include <iostream>

using namespace std;

void solve() {
    string x;
    cin >> x;
    int l = x.size();
    if(l==1){
        if(x[0]!='Y'&&x[0]!='e'&&x[0]!='s'){
            cout<<"NO\n";
            return;
        }
    }
    for (int i = 0; i < l - 1; i++) {
        if (x[i] == 'Y') {
            if (x[i + 1] != 'e') {
                cout << "No\n";
                return;
            }
            continue;
        }
        if (x[i] == 'e') {
            if (x[i+1] != 's') {
                cout << "No\n";
                return;
            }
            continue;
        }
        if (x[i] == 's') {
            if (x[i+1] != 'Y') {
                cout << "No\n";
                return;
            }
            continue;
        }
        cout << "No\n";
        return;
    }
    cout << "Yes\n";
}

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

B. Lost Permutation

题意:给一段数组,添加x个数(x随便)总和一定,求是否后面可以变成一个排列

思路:拿一个来记录之前的,然后减就行

#include <bits/stdc++.h>

using namespace std;

void solve() {
    int n, x;
    vector<bool> a(n + 100, false);
    cin >> n >> x;
    int ma = 0;
    for (int i = 0; i < n; i++) {
        int b;
        cin >> b;
        ma = max(ma, b);
        a[b] = true;
    }
    for (int i = 1; i < ma; i++) {
        if (!a[i]) {
            x -= i;
        }
    }
    while (x > 0) {
        x -= ++ma;
    }
    if (x == 0) {
        cout << "YES\n";
    } else {
        cout << "NO\n";
    }
}

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

C. Thermostat

题意:最小变化是x,范围a-b

思路:很明显就是三种情况ifelse就行

#include <bits/stdc++.h>

using namespace std;

void solve() {
    int l, r, x;
    cin >> l >> r >> x;
    int a, b;
    cin >> a >> b;
    if (a == b) {
        cout << "0\n";
        return;
    }
    if (abs(a - b) >= x) {
        cout << "1\n";
        return;
    }
    int x1 = a - l, x2 = b - l, y1 = r - a, y2 = r - b;
    if ((x1 >= x && x2 >= x) || (y1 >= x && y2 >= x)) {
        cout << "2\n";
        return;
    }
    int ma1 = max(x1, y1), ma2 = max(x2, y2);
    if (ma1 >= x && ma2 >= x) {
        cout << "3\n";
        return;
    }
    cout << "-1\n";
}

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

D. Make It Round

有人当sb把mn输反了

题意:求有最多0的数

思路:相当于找10的指数次方倍,满足
$$
t/gcd(t,n) \leq m的最大值t,假设d=t/gcd(t,n),n扩大(m/d)*d倍时就是所求
$$

板子:

int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}
#include <bits/stdc++.h>

using namespace std;
#define int long long

int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}

void solve() {
    int m, n;
    cin >> n >> m;
    int t = 1;
    while (t / gcd(t, n) <= m) t *= 10;
    t /= 10;//多乘了一个
    int d = t / gcd(t, n);
    cout << n * (m / d) * d << endl;
}

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

E. The Humanoid

题意:吸收一名力量严格小于人形力量的宇航员; 如果还有绿色血清,则使用绿色血清,使用蓝色血清,如果还有剩余的话。在不使用血清的情况下吸收到的就是a[i]/2,使用绿色血清就是×2蓝色血清×3

思路:就是一道dfs遍历就行(补题的时候一看如此简单在想为什么没写--当傻逼了,没读这题,D数学证明想太久了还犯了个致命错误)

#include <bits/stdc++.h>

using namespace std;
#define int long long
int a[200010];
int n;

int dfs(int st, int green, int blue, int h) {
    int res = 0;
    for (int i = st; i <= n; i++) {
        if (a[i] < h) {
            h += a[i] / 2;
            res++;
        } else {
            int ch = 0;
            if (green) {
                ch = max(ch, dfs(i, green - 1, blue, h * 2));
            }
            if (blue) {
                ch = max(ch, dfs(i, green, blue - 1, h * 3));
            }
            return ch + res;
        }
    }
    return res;
}

void solve() {
    int h;
    cin >> n >> h;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    sort(a + 1, a + n + 1);
    cout << dfs(1, 2, 1, h) << "\n";
}

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

标签:cout,834,int,Codeforces,--,while,solve,Div,gcd
From: https://www.cnblogs.com/bbbbear/p/17911284.html

相关文章

  • Codeforces Round 839 (Div. 3)
    CodeforcesRound839(Div.3)A.A+B?跳过太水了、、、、、#include<bits/stdc++.h>usingnamespacestd;intmain(){intt;cin>>t;while(t--){inta,b;scanf("%d+%d",&a,&b);cout<<a+......
  • 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......