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

Codeforces Round 863 (Div. 3)

时间:2023-12-17 16:45:10浏览次数:32  
标签:int 863 Codeforces cin -- while solve Div include

Codeforces Round 863 (Div. 3)

A. Insert Digit

题意:插入一个字母使得这个数字最大化

思路:只要从前往后便利就行

#include <iostream>

using namespace std;

void solve() {
    int n, k;
    cin >> n >> k;
    bool x = true,y=false;
    for (int i = 0; i < n; i++) {
        char b;
        cin >> b;
        int a = b - '0';
        if (a < k && x) {
            cout << k;
            x = false;
        }
        cout << a;
    }
    if (x) {
        cout << k;
    }
    cout << "\n";
}

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

B. Conveyor Belts

题意:从(x1,y1)到(x2,y2)所需能量,每变换一次轨道需要能量

思路:确定是哪个轨道就行

#include <iostream>
#include <cmath>

using namespace std;

void solve() {
    int n = 0, x1 = 0, x2 = 0, y1 = 0, y2 = 0;
    cin >> n >> x1 >> y1 >> x2 >> y2;
    int a1 = min(x1, min(n - x1 + 1, min(y1, n - y1 + 1)));
    int a2 = min(x2, min(n - x2 + 1, min(y2, n - y2 + 1)));
    cout << abs(a1 - a2) << "\n";
}

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

C. Restore the Array

*前面卡了一会因为以为a的长度是不确定的,但是他是确定的读题很重要!!!!!!!

题意:给你一个b数组他是由a数组两个相邻元素的最大值而决定且b的长度为n-1,a的长度为n

思路:Cache_-669f9c0da09f2d89.

#include <bits/stdc++.h>

using namespace std;

const int MAX = 2e5 + 10;
int a[MAX];

void solve() {
    int n;
    cin >> n;
    bool x = true;
    for (int i = 1; i < n; i++) {
        cin >> a[i];
    }
    a[0] = a[1];
    a[n] = a[n - 1];
    for (int i = 0; i < n; i++) {
        cout << min(a[i], a[i + 1]) << " ";
    }
    cout << "\n";
}

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

D. Umka and a Long Flight

题意:给一个长方形他的边长是斐波那契数列(典中典就不描述了),然后给定一个坐标(x,y),问能否最后剩下这个坐标上的方形为1*1,分割的矩形中有个要求:有一个矩阵为正方形而且其边长是等于斐波那契的

思路:img

imgimg

ps:以上为题目给的图(讲真看了这图我觉得这个题目难度至少下降两个level)

按照斐波那契来分割矩形(边割边转(坐标问题画图理解就是了))

#include <bits/stdc++.h>

using namespace std;
#define int long long
int dp[55];

void fab() {
    dp[0] = 1;
    dp[1] = 1;
    for (int i = 2; i <= 45; i++) {
        dp[i] = dp[i - 1] + dp[i - 2];
    }
}

bool cut(int n, int x, int y) {
    if (n == 1) return true;
    int mid = dp[n + 1] / 2;
    if (y <= mid) y = dp[n + 1] - y + 1;
    if (y <= dp[n]) return false;
    return cut(n - 1, y - dp[n], x);
}

void solve() {
    int n, x, y;
    cin >> n >> x >> y;
    if (cut(n, x, y)) cout << "Yes\n";
    else cout << "NO\n";
}

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

E. Living Sequence

题意:简单来说就是一旦数字里面有一个位数含有4就跳过

第一眼dp,第二眼1e12怎么dp,不会!gg

思路:没有4,就相当于将10进制变成了9进制,然后每个数组映射(太妙了kao)

#include <bits/stdc++.h>

using namespace std;
#define int long long
int a[22];
int x[10] = {0, 1, 2, 3, 5, 6, 7, 8, 9};

void solve() {
    int n;
    cin >> n;
    int cnt = 0;
    while (n) {
        a[++cnt] = x[n % 9];
        n /= 9;
    }
    for (int i = cnt; i > 0; i--) {
        cout << a[i];
    }
    cout << "\n";
}

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

后面的题慢慢补,每道题只有三位数太夸张

标签:int,863,Codeforces,cin,--,while,solve,Div,include
From: https://www.cnblogs.com/bbbbear/p/17909283.html

相关文章

  • 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;......
  • Codeforces Round 816 (Div. 2) VP
    基本情況A秒了,B错一次之后也过了,C没思路。B.BeautifulArrayProblem-B-Codeforcesvoidsolve(){ longlongn,k,b,s; memset(ans,0,sizeof(ans)); std::cin>>n>>k>>b>>s; if(s<b*k){std::cout<<"-1\n";ret......
  • Codeforces Round 815 (Div. 2)
    基本情况脑子太不清楚了。A题有思路,但是各种细节问题(数论题太不熟练了),错了好几次才过。B题直接分析数据愣猜一个解,猜对了。A.BurenkaPlayswithFractionsProblem-A-Codeforces难点在分析输出\(1\)的情况。我的想法是通分,然后直接比分子是否互相整除,想法很对,但是......
  • Codeforces Round 915 (Div. 2)
    A.ConstructiveProblems看了一眼数据,猜测可能是n,m里的最大#include<bits/stdc++.h>usingnamespacestd;voidsolve(){ inta,b; cin>>a>>b; intans=max(a,b); cout<<ans<<"\n";}intmain(){ ios::sync_with_stdio(false);cin.tie......
  • Codeforces Round 915 (Div. 2)
    CodeforcesRound915(Div.2)唉,菜狗。A-CoverinWaterintmain(){IOS;for(cin>>_;_;--_){cin>>n>>m;cout<<max(n,m)<<'\n';}return0;}B-Begginer'sZelda除......
  • Educational Codeforces Round 159 (Rated for Div. 2) C. Insert and Equalize (贪心+
    EducationalCodeforcesRound159(RatedforDiv.2)C.InsertandEqualize思路:首先对\(a\)进行排序,然后对所有差值取gcd,获得可用的最大因子\(gc\),答案有两种情况:一种是\(a_{n+1}\)在$a_1\(~\)a_n$范围内,这时要获得最大的位置一种情况是$a_1\(~\)a_n$......
  • [Codeforces] CF1774B Coloring
    CF1774BColoring题意Cirno_9baka的纸条上有\(n\)个格子,他觉得空白的纸条看着有点无趣,于是想在纸条的格子上涂上\(m\)种颜色。同时,他认为第\(i\)种颜色必须要用\(a_i\)次,且每连续\(k\)个格子里涂的颜色必须互不相同。Cirno_9baka想知道有没有这样的一种涂色方案能......
  • [Codeforces] CF1760F Quests
    CF1760FQuests题意有\(n\)个任务,你每一天都可以选择其中的一个任务完成或不选。当你完成了第\(i\)个任务,你将获得\(a_i\)元。但是如果你今天完成了一个任务,那么你之后\(k\)天内都不能再完成这个任务。给出两个数\(c\),\(d\),要求求出满足在\(d\)天内可以收集至少\(c......
  • [Codeforces] CF1744E1 Divisible Numbers (easy version)
    CF1744E1DivisibleNumbers(easyversion)题意给你四个数\(a,b,c,d\),你需要找出一组\(x,y\)使得\(a<x\leqc,b<y\leqd\)并且\(x\cdoty\)能被\(a\cdotb\)整除,如果没有输出-1-1。思路最暴力的思路肯定是枚举,更肯定的一点是会TLE但是注意到,如果\(x\)一定,那么他......