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

Codeforces Round 863 (Div. 3)

时间:2023-04-05 17:13:25浏览次数:37  
标签:ch int 863 Codeforces fib while && Div getchar

A. Insert Digit

放在第一个比他小的数前面

#include <bits/stdc++.h>

using namespace std;

void solve() {
    int n, d;
    cin >> n >> d;
    string s;
    cin >> s;
    for (char i: s) {
        if (d > i - '0') cout << d, d = -1;
        cout << i;
    }
    if (d != -1) cout << d;
    cout << "\n";
    return;
}

int32_t main() {
    ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
    int t;
    cin >> t;
    for (; t; t--)
        solve();
    return 0;
}

B. Conveyor Belts

计算两个点分别在第几圈就行了

#include <bits/stdc++.h>

using namespace std;

#define int long long

int read() {
    int x = 0, f = 1, ch = getchar();
    while ((ch < '0' || ch > '9') && ch != '-') ch = getchar();
    if (ch == '-') f = -1, ch = getchar();
    while (ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + ch - '0', ch = getchar();
    return x * f;
}

void solve() {
    int n = read(), m = n / 2, a = read(), b = read(), c = read(), d = read();
    if (a > m) a = n - a + 1;
    if (b > m) b = n - b + 1;
    if (c > m) c = n - c + 1;
    if (d > m) d = n - d + 1;
    printf("%lld\n", abs(min(a, b) - min(c, d)));
}

int32_t main() {

    for (int t = read(); t; t--)
        solve();
    return 0;
}

C. Restore the Array

如果\(b_i=b_{i+1}\)则一定满足\(a_{i+1} = b_{i}\),先把这些位置都填完之后再根据条件填入较小值就可以了

#include <bits/stdc++.h>

using namespace std;

#define int long long

int read() {
    int x = 0, f = 1, ch = getchar();
    while ((ch < '0' || ch > '9') && ch != '-') ch = getchar();
    if (ch == '-') f = -1, ch = getchar();
    while (ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + ch - '0', ch = getchar();
    return x * f;
}

void solve() {
    int n = read();
    vector<int> a(n + 1, -1), b(n);
    for (int i = 1; i < n; i++) b[i] = read();
    a[1] = b[1], a[n] = b[n - 1];
    for (int i = 2; i < n; i++)
        if (b[i - 1] == b[i]) a[i] = b[i];
        else a[i] = min(b[i - 1], b[i]);
    for (int i = 1; i <= n; i++) printf("%lld ", a[i]);
    printf("\n");
    return;
}

int32_t main() {

    for (int t = read(); t; t--)
        solve();
    return 0;
}

D. Umka and a Long Flight

对于这个矩形满足\(h<w\),所以要减去一个正方形一定是一个\(h\times h\)的,如果这个点在左边就减去右边,如果在右边就对称到左边再减去右边,如果在中间就就寄了。减完之后一定满足\(h>w\),为了方便递归操作可以交换横纵坐标。

#include<bits/stdc++.h>

using namespace std;

int read() {
    int x = 0, f = 1, ch = getchar();
    while ((ch < '0' || ch > '9') && ch != '-') ch = getchar();
    if (ch == '-') f = -1, ch = getchar();
    while (ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + ch - '0', ch = getchar();
    return x * f;
}

vector<int> fib(46);

bool check( int n , int x , int y ){
    if( n == 0 ) return true;
    if( y > fib[n-1] ) y = fib[n+1] - y + 1;
    if( y > fib[n-1] ) return false;
    return check( n-1 , y , x );
}

int32_t main() {

    fib[0] = fib[1] = 1;
    for( int i = 2 ; i <= 45 ; i ++ ) fib[i] = fib[i-1] + fib[i-2];
    for( int t = read() , n , x , y ; t ; t -- ){
        n = read() , x = read() , y = read();
        printf( check( n , x , y ) ? "YES\n" : "NO\n" );
    }
    return 0;
}

E. Living Sequence

把十进制转换成九进制。如果一位数字\(d\)满足\(d>3\)把\(d=d+1\)即可

#include <bits/stdc++.h>

using namespace std;

#define int long long

int read() {
    int x = 0, f = 1, ch = getchar();
    while ((ch < '0' || ch > '9') && ch != '-') ch = getchar();
    if (ch == '-') f = -1, ch = getchar();
    while (ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + ch - '0', ch = getchar();
    return x * f;
}

void solve() {
    int n = read();
    vector<int> a;
    while (n) a.push_back(n % 9), n /= 9;
    for (int &i: a)
        if (i > 3) i = i + 1;
    reverse(a.begin(), a.end());
    for( auto i : a )
        cout << i;
    cout << '\n';
    return;
}

int32_t main() {

    for (int t = read(); t; t--)
        solve();
    return 0;
}

标签:ch,int,863,Codeforces,fib,while,&&,Div,getchar
From: https://www.cnblogs.com/PHarr/p/17289813.html

相关文章

  • Codeforces Round 640 (Div. 4) ABCDEFG
    https://codeforces.com/contest/1352不知道怎么的复制过来的代码容易歪,观看效果可能不大好。这场古早div4,大题极其友好,除了E卡空间卡到我爆炸,别的都体验感极好。A.SumofRoundNumbers#include<bits/stdc++.h>usingnamespacestd;typedeflonglongLL;typedefpai......
  • Codeforces Round 863 (Div. 3) A-C 赛后思路复盘
    A(思维)思路:观察样例可知数越大放在前面越优。遍历字符串,判断当前位置的数字和要插入的数字的关系,如果要插入的数大于当前数,那么就插入到当前数的前面。string里有一个insert函数,可以把指定字符串插入到指定下标之前。在原串下标为pos的字符前插入字符串strbasic_string&insert......
  • cf-div.3-863d
    题目链接:https://codeforces.com/contest/1811/problem/D思维题,昨天被E题搞太久了,这题认真想的话应该可以出的。思路:不断循环,判断x和y是否在合法区间内。代码:#include<bits/stdc++.h>usingnamespacestd;constintN=2e5+10;longlongfib[70];voidsolve(){int......
  • codeforces round 862
    A.和洛谷上的删数思路一致,后者是找峰顶,这个是找谷底从前到后枚举每一位与要添加的数比大小,如果要添加的数<=该位的数,就继续枚举,否则就将这个数添加在其前面B.需要移动的步数=两个点所在的层数之差的绝对值,只要计算出所在层数就可以一开始没想明白怎么算这个层数,先把每个......
  • Codeforces Round 861 (Div. 2)
    Preface这场感觉都是一个礼拜前补题打的了,但由于上周末事情比较多都没来得及写题解因此可能题意都记得不是很清楚了,就简略地谈一谈吧A.LuckyNumbers不难想到直接暴力从左端点枚举到右端点并对每个数进行暴力判断一个很naive的结论就是当答案为\(9\)时直接输出即可,然后我们......
  • Codeforces Round 862 A-E
    CodeforcesRound862(Div.2)先简单写一下A-E的题解。A异或的经典性质:\(x\oplusx=0\)。B显然要把字典序最小的那个字母放到最前面。如果这个字母出现了很多次,那么应该选择最后一次出现的位置。这也很容易证明。C联立以后计算一下就行了。比赛的时候爆了一次int。......
  • Codeforces Round 717 (Div. 2) B. AGAGA XOOORRR(位运算)
    https://codeforces.com/contest/1516/problem/B题目大意:给定长度为n的数组a,问我们能不能一直选择两个相邻的元素进行异或后,删除这两个值,把异或值留下来,最后剩下>=2个数字,它们都是相同的?可以做到输出YES,不能的话输出NO。input23022423110outputYESNO题......
  • CodeTON Round 4 (Div. 1 + Div. 2, Rated, Prizes!)-C
    参考了佬的c题题解思路,感觉很巧妙,记录一下https://zhuanlan.zhihu.com/p/618685370#include<bits/stdc++.h>usingnamespacestd;#defineintlonglongconstintN=2*100010;inta[N];voidsolve(){ intn,c,d; cin>>n>>c>>d; set<int>se......
  • Multimedia (MP3, MPEG-4, AVI, DiVX, etc.) support in Ubuntu 12.04 (Precise)
    Whydoesn’tUbuntusupportMP3‘outofthebox’?UbuntucannotincludesupportforMP3orDVDvideoplaybackorrecording.MP3formatsarepatented,andthepatentholdershavenotprovidedthenecessarylicenses.Ubuntualsoexcludesothermultimediasof......
  • cf-div.2-862d
    题目链接:https://codeforces.com/contest/1805/problem/D赛时没过的题。思路:首先发现一个性质:对于k来说,如果树上的一个点到树的直径的两个端点的距离都小于k的话,那么这个点一定是一个孤立点。证明:采用反证法:假设\(x,y\)为树的直径的两个端点,\(a,b\)为另外两个点,且有\(d[a][x]<k......