首页 > 其他分享 >Codeforces Round 956 (Div. 2)

Codeforces Round 956 (Div. 2)

时间:2024-07-08 11:11:52浏览次数:12  
标签:cin int Codeforces 956 ++ while vector solve Div

A. Array Divisibility

Array Divisibility
直接输出1到n

#include <bits/stdc++.h>
using namespace std;

void solve() {
    int n;
    cin >> n;

    for (int i = 1; i <= n; i++) {
        cout << i << (i == n ? '\n' : ' ');
    }
}

int main(void)
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

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

    return 0;
}

B. Corner Twist

Corner Twist
每一次都使用2*2的方块进行操作,判断将前(n-1)*(m-1)方块复原后是否相等就可以了

#include <bits/stdc++.h>
using namespace std;

void solve() {
    int n, m;
    cin >> n >> m;

    vector<string> s1(n);
    for (int i = 0; i < n; i++) {
        cin >> s1[i];
    }

	vector<string> s2(n);
    for (int i = 0; i < n; i++) {
        cin >> s2[i];
    }

    vector a(n, vector<int>(m));
    vector b(n, vector<int>(m));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            a[i][j] = s1[i][j] - '0';
            b[i][j] = s2[i][j] - '0';
        }
    }

    for (int i = 0; i < n - 1; i++) {
        for (int j = 0; j < m - 1; j++) {
            while (a[i][j] != b[i][j]) {
                a[i][j] = (a[i][j] + 1) % 3;
                a[i][j + 1] = (a[i][j + 1] + 2) % 3;
                a[i + 1][j] = (a[i + 1][j] + 2) % 3;
                a[i + 1][j + 1] = (a[i + 1][j + 1] + 1) % 3;
            }
        }
    }

    int ans = 1;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            if (a[i][j] != b[i][j]) {
                ans = 0;
            }
        }
    }

    if (ans) {
        cout << "YES\n";
    } else {
        cout << "NO\n";
    }
}

int main(void)
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

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

    return 0;
}

C. Have Your Cake and Eat It Too

Have Your Cake and Eat It Too
暴力枚举六种吃蛋糕的顺序即可,注意向上取整,代码写的非常丑陋

#include <bits/stdc++.h>
using namespace std;

void work(int n, long long sum, vector<int> &l, vector<int> &r, vector<long long> &a, vector<long long> &b, vector<long long> &c) {
    int ll = 0, rr = 1;
    while (rr <= n && a[rr] - a[ll] < sum) {
        rr++;
    }
    if (rr <= n) {
        l.push_back(ll + 1);
        r.push_back(rr);
    }

    ll = rr;
    rr = ll + 1;
    while (rr <= n && b[rr] - b[ll] < sum) {
        rr++;
    }
    if (rr <= n) {
        l.push_back(ll + 1);
        r.push_back(rr);
    }

    ll = rr;
    rr = n;
    if (c[rr] - c[ll] >= sum) {
        l.push_back(ll + 1);
        r.push_back(rr);
    }
}

void solve() {
    int n;
    cin >> n;

    vector<long long> a(n + 1), b(n + 1), c(n + 1);
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    for (int i = 1; i <= n; i++) {
        cin >> b[i];
    }
    for (int i = 1; i <= n; i++) {
        cin >> c[i];
    }

    long long sum = 0;
    for (int i = 1; i <= n; i++) {
        sum += a[i];
    }
    sum = (sum + 2) / 3;

    for (int i = 0; i < n; i++) {
        a[i + 1] += a[i];
        b[i + 1] += b[i];
        c[i + 1] += c[i];
    }

    vector<int> l, r;

    work(n, sum, l, r, a, b, c);
    if (l.size() == 3) {
        cout << l[0] << ' ' << r[0] << ' ';
        cout << l[1] << ' ' << r[1] << ' ';
        cout << l[2] << ' ' << r[2] << '\n';
        return;
    }

    l.clear(); r.clear();
    work(n, sum, l, r, a, c, b);
    if (l.size() == 3) {
        cout << l[0] << ' ' << r[0] << ' ';
        cout << l[2] << ' ' << r[2] << ' ';
        cout << l[1] << ' ' << r[1] << '\n';
        return;
    }

    l.clear(); r.clear();
    work(n, sum, l, r, b, a, c);
    if (l.size() == 3) {
        cout << l[1] << ' ' << r[1] << ' ';
        cout << l[0] << ' ' << r[0] << ' ';
        cout << l[2] << ' ' << r[2] << '\n';
        return;
    }

    l.clear(); r.clear();
    work(n, sum, l, r, b, c, a);
    if (l.size() == 3) {
        cout << l[2] << ' ' << r[2] << ' ';
        cout << l[0] << ' ' << r[0] << ' ';
        cout << l[1] << ' ' << r[1] << '\n';
        return;
    }

    l.clear(); r.clear();
    work(n, sum, l, r, c, b, a);
    if (l.size() == 3) {
        cout << l[2] << ' ' << r[2] << ' ';
        cout << l[1] << ' ' << r[1] << ' ';
        cout << l[0] << ' ' << r[0] << '\n';
        return;
    }

    l.clear(); r.clear();
    work(n, sum, l, r, c, a, b);
    if (l.size() == 3) {
        cout << l[1] << ' ' << r[1] << ' ';
        cout << l[2] << ' ' << r[2] << ' ';
        cout << l[0] << ' ' << r[0] << '\n';
        return;
    }

    cout << -1 << endl;
}

int main(void)
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

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

    return 0;
}

标签:cin,int,Codeforces,956,++,while,vector,solve,Div
From: https://www.cnblogs.com/foolnine/p/18289507

相关文章

  • CodeForces CF1986C Update Queries题解
    来吧,兄弟们,再来篇题解,其实也不是题解,是我自己的思路/心得/体会UpdateQueries题面翻译题目翻译一共$t$组数据,每组数据给定长度为$n$的字符串$s$,长度为$m$的$ind$数组和字符串$c$。你可以任意安排$ind$数组和字符串$c$的顺序,并按照此顺序对字符串$s$进行$m$......
  • **CodeForces CF1928B Equalize题解**
    ok兄弟们,今天本蒟蒻来做一篇小小的题解Equalize题面翻译有一个给定的长度为$n$的数列$a$,现在加上一个排列$b$,即$c_i=a_i+b_i$。现在求对于所有可能的$b$,$c$中出现最多的数的出现次数的最大值。translateby@UniGravity.题目描述Vasyahastwohobbies—addingpe......
  • codeforces1849 D. Array Painting
    题目链接https://codeforces.com/problemset/problem/1849/D题意输入\(n(1\leqn\leq2e5)\)和长为\(n\)的数组\(a(0\leqa[i]\leq2)\)。最初,数组的每个元素都是蓝色的。有两种类型的操作:支付一枚硬币,选择一个蓝色元素,将其涂成红色。选择一个不等于\(0\)的红......
  • Educational Codeforces Round 167 (Rated for Div. 2)
    A容易发现由于玩家是八向移动,-1以及其上的硬币都可以接到,但是往下都无法。B子序列不需要连续,子串则必须连续,那么我们可以考虑对子串进行遍历,相当于遍历起点,求出子序列能和其对上的最大长度,然后用子串长度加上子序列的长度减去重合长度即可。C赛时C没D出的快,想贪心策略想......
  • Codeforces Round 951 (Div. 2)
    Preface这场由于下午四点约好了和祁神打乒乓球,因此两点开了一场VP,结果困得要死D题一个特判写挂了没看出来调了贼久然后E题秒出正解,但因为一个极其傻逼的地方挂了又没调出来,鉴定为纯纯的飞舞A.GuesstheMaximum签到,每次选的一定是相邻的两个#include<cstdio>#include<iost......
  • 沪越联赛 - 2024年6月月赛Div2 题解
    问题A:替换题目描述小明每次注释的时候都写\(n\)个/。小红看了小明的程序,觉得太难看了,那么多/,所以决定把这些没用的/都去掉。小红定义了一个宏命令,每次可以将所有连续的\(m\)个/替换成空(注意不是空格)小明得知了小红的企图后非常着急,因为他知道光把/都去掉,那么原......
  • YOLOv8改进 | Conv篇 | 添加DiverseBranchBlock多元分支模块(有效涨点,重参数化模块高效
    鱼弦:公众号【红尘灯塔】,CSDN博客专家、内容合伙人、新星导师、全栈领域优质创作者、51CTO(Top红人+专家博主)、github开源爱好者(go-zero源码二次开发、游戏后端架构https://github.com/Peakchen)YOLOv8改进|Conv篇|添加DiverseBranchBlock多元分支模块(有效涨点,重参数......
  • HT-014 Div3 扫雷 题解 [ 绿 ] [ 二维差分 ]
    分析观察到是曼哈顿距离\(\ler\)的范围可以扫到,联想到如下图形:左边是\(r=1\)可以扫到的范围,右边是\(r=2\)可以扫到的范围。于是,我们只要对这样的图形在\(1000*1000\)的格子里差分一下就好了。但这样的复杂度是\(O(nm)\)的,会死的很惨。优化不难发现这个图形是一......
  • HT-014 Div3 跳棋 题解 [ 黄 ] [ 并查集 ] [ 树型结构 ]
    分析依旧是一个连通块题。观察题面不难发现两个重要性质:一个跳棋只能以它旁边的两个跳棋为中点跳跃,且满足跳跃路线中除中点以外没有其它跳棋阻挡。只有我们的跳棋可以移动。跳棋的操作具有可逆性/对称性。第三条性质可以这么理解,就是一个跳棋跳过去之后,它还可以跳回来。......
  • P9565 [SDCPC2023] Not Another Path Query Problem
    P9565[SDCPC2023]NotAnotherPathQueryProblem位运算+并查集从价值至少为\(V\)入手,枚举一段二进制上长为\(i\)的前缀,第\(i+1\)位取\(1\),并且比\(V\)要大,这样\(i+1\)之后的位就可以任意取了(不妨现在都先为\(0\)),设这样构成的二进制串为\(s\)。考虑按位与的性质......