首页 > 其他分享 >「解题报告」AtCoder Beginner Contest 313

「解题报告」AtCoder Beginner Contest 313

时间:2023-08-06 21:24:46浏览次数:41  
标签:AtCoder ch Beginner Contest int long ++ yifan getchar

比赛地址:AtCoder Beginner Contest 313 - AtCoder

后记:请正确理解题意后再做题!!!

A - To Be Saikyo

A - To Be Saikyo (atcoder.jp)

每个人有一个数值,问第一个人要加多少才能使得自己的数值变成最大的。

就这么个破题我还 WA 了一发

//The code was written by yifan, and yifan is neutral!!!

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define bug puts("NOIP rp ++!");

template<typename T>
inline T read() {
    T x = 0;
    bool fg = 0;
    char ch = getchar();
    while (ch < '0' || ch > '9') {
        fg |= (ch == '-');
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9') {
        x = (x << 3) + (x << 1) + (ch ^ 48);
        ch = getchar();
    }
    return fg ? ~x + 1 : x;
}

const int N = 110;

int n, maxx, cnt;
int p[N];

int main() {
    n = read<int>();
    for (int i = 1; i <= n; ++ i) {
        p[i] = read<int>();
        if (maxx == p[i]) {
            ++ cnt;
        } else {
            maxx = max(maxx, p[i]);
            cnt = 1;
        }
    }
    sort(p + 2, p + n + 1, greater<int>());
    if (p[2] < p[1]) {
        puts("0");
    } else {
        cout << p[2] - p[1] + 1 << '\n';
    }
    return 0;
}

B - Who is Saikyo?

B - Who is Saikyo? (atcoder.jp)

给你一些关系 \((a, b)\),代表 \(a\) 比 \(b\) 强。问最强的人,无法判断则输出 \(-1\)。

判断入度为 \(0\) 的点的个数即可。

//The code was written by yifan, and yifan is neutral!!!

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define bug puts("NOIP rp ++!");

template<typename T>
inline T read() {
    T x = 0;
    bool fg = 0;
    char ch = getchar();
    while (ch < '0' || ch > '9') {
        fg |= (ch == '-');
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9') {
        x = (x << 3) + (x << 1) + (ch ^ 48);
        ch = getchar();
    }
    return fg ? ~x + 1 : x;
}

int n, m, maxx;
int in[100];

int main() {
    n = read<int>(), m = read<int>();
    for (int i = 1, a, b; i <= m; ++ i) {
        cin >> a >> b;
        ++ in[b];
    }
    for (int i = 1; i <= n; ++ i) {
        if (!in[i]) {
            if (maxx) {
                puts("-1");
                return 0;
            }
            maxx = i;
        }
    }
    cout << maxx << '\n';
    return 0;
}

C - Approximate Equalization 2

C - Approximate Equalization 2 (atcoder.jp)

有一个操作,选择最大的数和最小的数,然后最小的数加一,最大的数减一,问最少操作多少次,可以使得最大的数和最小的数差值最大是 \(1\)。

求商和余数,有多少个余数就代表有多少个数只到达商 \(+ 1\) 的位置。

//The code was written by yifan, and yifan is neutral!!!

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define bug puts("NOIP rp ++!");

template<typename T>
inline T read() {
    T x = 0;
    bool fg = 0;
    char ch = getchar();
    while (ch < '0' || ch > '9') {
        fg |= (ch == '-');
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9') {
        x = (x << 3) + (x << 1) + (ch ^ 48);
        ch = getchar();
    }
    return fg ? ~x + 1 : x;
}

const int N = 2e5 + 5;

ll sum, ans;
ll a[N];

int main() {
    int n = read<int>();
    for (int i = 1; i <= n; ++ i) {
        a[i] = read<ll>();
        sum += a[i];
    }
    sort(a + 1, a + n + 1);
    ll res = sum % n, zc = sum / n;
    for (int i = 1; i <= n - res; ++ i) {
        ans += abs(zc - a[i]);
    }
    for (int i = n - res + 1; i <= n; ++ i) {
        ans += abs(a[i] - zc - 1);
    }
    cout << ans / 2 << '\n';
    return 0;
}

D - Odd or Even

D - Odd or Even (atcoder.jp)

这是一道交互题,本人是第一次做这种新题型。

题目大意:有一个序列 \(A\),每一个元素只可能是 \(0\) 或者 \(1\),现在,你可以从中任选 \(k\) 个位置,通过询问这 \(k\) 个位置的数它们的和的奇偶性,来判断每个元素是 \(0\) 还是 \(1\)。

对于前 \(k + 1\) 个数,我们一共选 \(k + 1\) 次,第 \(i\) 次空出第 \(i\) 个位置,计算出这些数的奇偶性,再依次异或,来得出前 \(k + 1\) 个数的奇偶性,后面的数只要把最后一个数换掉即可。

//The code was written by yifan, and yifan is neutral!!!

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define bug puts("NOIP rp ++!");

template<typename T>
inline T read() {
    T x = 0;
    bool fg = 0;
    char ch = getchar();
    while (ch < '0' || ch > '9') {
        fg |= (ch == '-');
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9') {
        x = (x << 3) + (x << 1) + (ch ^ 48);
        ch = getchar();
    }
    return fg ? ~x + 1 : x;
}

const int N = 1010;

int n, k;
int ans[N];

void out(vector<int> x) {
    int siz = x.size();
    for (int i = 0; i < siz; ++ i) {
        cout << x[i] << " \n"[i + 1 == siz];
    }
}

int main() {
    n = read<int>(), k = read<int>();
    auto send = [&](vector<int> v) {
        for (int &x : v) {
            ++ x;
        }
        cout << "? ";
        out(v);
        cout.flush();
        int x;
        x = read<int>();
        return x;
    };
    vector<int> ans(n);
    int r = 0;
    for (int i = 0; i < k + 1; ++ i) {
        vector<int> v;
        for (int j = 0; j < k + 1; ++ j) {
            if (i != j) {
                v.emplace_back(j);
            }
        }
        ans[i] = send(v);
        r ^= ans[i];
    }
    for (int i = 0; i < k + 1; ++ i) {
        ans[i] ^= r;
    }
    vector<int> v(k);
    int s = 0;
    for (int i = 0; i < k - 1; ++ i) {
        v[i] = i;
        s ^= ans[i];
    }
    for (int i = k + 1; i < n; ++ i) {
        v.back() = i;
        int t = send(v);
        ans[i] = s ^ t;
    }
    cout << "! ";
    out(ans);
    cout.flush();
    return 0;
}

E 的题目……说实话,没读懂……

标签:AtCoder,ch,Beginner,Contest,int,long,++,yifan,getchar
From: https://www.cnblogs.com/yifan0305/p/17610064.html

相关文章

  • AtCoder Beginner Contest (ABC) 313 D-E
    Tasks-AtCoderBeginnerContest313PS:当时看到D过的比E多就一直在考虑D,但还没做出来,其实个人感觉E比D简单。 D-OddorEven交互题。有n个数,最多可以询问n次然后要求判断出这n个数的奇偶性。每次可以询问数组里任意k个元素的和是不是奇数一开始想到的是高斯消元,n次总能......
  • AtCoder Beginner Contest 313 A-E Code
    比赛链接:AtCoderBeginnerContest313-AtCoder A:#include<bits/stdc++.h>usingnamespacestd;intmain(){cin.tie(0);ios::sync_with_stdio(false);intn;cin>>n;intp1;cin>>p1;intma......
  • Practice on Codeforces and Atcoder in August
    EducationalCodeforcesRound151A~ECodeforcesRound#879Div.2CodeforcesRound#882Div.2CodeforcesRound#873Div.2......
  • Toyota Programming Contest 2023#4(AtCoder Beginner Contest 311)
    Preface补下好久之前打的比赛博客这场前面都写的挺稳的,然后一到G就降智了没写出来A-FirstABC签到#include<cstdio>#include<iostream>#include<utility>#include<vector>#include<cstring>#include<cmath>#include<algorithm>#include<queue>#i......
  • SMU Summer 2023 Contest Round 9(2019 山东省大学生程序设计竞赛)
    2019山东省大学生程序设计竞赛A.Calandar纯模拟吧(感觉我做麻烦了(?),就是如果问的是未来的日期,就用相隔天数取模后加上这天的星期,如果问的是曾经的,就用这天的星期减去相隔天数的取模后的数,因为是减法,记得加模数#include<bits/stdc++.h>#defineintlonglong#defi......
  • SMU Summer 2023 Contest Round 6
    Problem-D.NumberOfPermutations传送门容斥原理思路:利用容斥,首先所有可能的排列肯定是fac[n],然后可能会有三种bad的情况:①第一个元素的排列是非递减②第二种是第二个元素的排列是非递减③这两个可能出现的重叠情况,意思就是说同时导致①②成立这个时候我们利用容斥......
  • SMU Summer 2023 Contest Round 1
    Problem-ATheContest(纯属眼瞎)#include<bits/stdc++.h>usingnamespacestd;typedeflonglongll;constintN=1e7+50,M=5050,mod=9901,MAX_N=1e3+50,INF=0x3f3f3f3f;constdoublePI=3.1415926;#defineIOSios_base::sync_with_stdio(f......
  • SMU Summer 2023 Contest Round 2
    Problem-ATreasureHunt#include<bits/stdc++.h>usingnamespacestd;typedeflonglongll;constintN=1e5+50,M=5e3+50,mod=9901,MAX_N=6e3+50,INF=0x3f3f3f3f;constdoublePI=3.1415926;#defineIOSios_base::sync_with_stdio(f......
  • SMU Summer 2023 Contest Round 3
    Problem-A-CurriculumVitae#include<bits/stdc++.h>usingnamespacestd;constintN=1e6+50,M=5050,mod=9901,MAX_N=1e3+50,INF=0x3f3f3f3f;#defineintlonglong#defineldlongdouble#defineIOSios_base::sync_with_stdio(false)......
  • nfls15095 Atcoder-abc123_d 蛋糕
    Atcoder-abc123_dAT小卖部从下学期开始售卖带有数字形状的蛋糕,\(X\),\(Y\)和\(Z\)种蛋糕分别带有\(1\)形,\(2\)形和\(3\)形蜡烛,而且每个蛋糕都有美味值,如下所示:带有\(1\)形蜡烛的美味值有:\(A_1,A_2,\cdots,A_X\)带有\(2\)形蜡烛的美味值有:\(B_1,B_2,\cdots,B_Y\)......