首页 > 其他分享 >Codeforces Round 920 (Div. 3)补题D~F

Codeforces Round 920 (Div. 3)补题D~F

时间:2024-01-17 12:33:42浏览次数:34  
标签:const int Alice back front 补题 920 Div Bob

Codeforces Round 920 (Div. 3)

D.

思路

取a最大和c最小的或c最小和a最大的匹配

ac代码

#include <bits/stdc++.h>

using namespace std;
using i64 = long long;
const i64 inf = 8e18;
typedef pair<int, int> pii;
const int mod = 1e9 + 7;
const int N = 2e6 + 10;

void solve() {
    int n, m; 
    cin >> n >> m;
    deque<i64> a(n), b(m);
    for (auto &i : a) cin >> i;
    for (auto &i : b) cin >> i;

    sort(a.begin(), a.end());
    sort(b.begin(), b.end());

    i64 ans = 0;
    while (a.size()) {
        if (abs(a.front() - b.back()) >= abs(b.front() - a.back())) {
            ans += abs(a.front() - b.back());
            a.pop_front();
            b.pop_back();
        } else {
            ans += abs(b.front() - a.back());
            b.pop_front();
            a.pop_back();
        }
    }

    cout << ans << endl;
}   

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    cout.tie(0);

    int t = 1;
    cin >> t;
    while (t --) solve();

    return 0;
}

D.

思路

可以看出来,当行数差为奇数时是Alice吃Bob,行数为偶数时是Bob吃Alice。先特判一下初始时Alice和Bob在同一行或Alice在Bob下面的情况,这种情况下就是平局。然后来看一般的情况。若是Alice吃Bob,当他们的列数差小于1时Alice必定吃到Bob,当他们列数差大于1时就要看Alice的操作次数和Alice离墙的距离;若是Bob吃Alice,当他们列数相等时Bob必定吃到Alice,否则就要看Bob的操作次数和他与墙距离的大小关系。

ac代码

#include <bits/stdc++.h>

using namespace std;
using i64 = long long;
const i64 inf = 8e18;
typedef pair<int, int> pii;
const int mod = 1e9 + 7;
const int N = 1e6 + 10;

void solve() {
    int h, w, xa, ya, xb, yb;
    cin >> h >> w >> xa >> ya >> xb >> yb;
    if (xa >= xb) cout << "Draw\n";
    else if ((xb - xa) % 2) {
        int t = (xb - xa + 1) / 2;//操作次数,因为Alice是先手,所以操作次数比Bob多一次
        if (abs(ya - yb) <= 1 || ya < yb && (w - ya) <= t || ya > yb && ya - 1 <= t) cout << "Alice\n";
        else cout << "Draw\n";
    } else {
        int t = (xb - xa) / 2;
        if (ya == yb || ya < yb && yb - 1 <= t || ya > yb && (w - yb) <= t) cout << "Bob\n";
        else cout << "Draw\n";
    }

}   

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    cout.tie(0);

    int t = 1;
    cin >> t;
    while (t --) solve();

    return 0;
}

F.

带权前缀和,根号分治

标签:const,int,Alice,back,front,补题,920,Div,Bob
From: https://www.cnblogs.com/kichuan/p/17969732

相关文章

  • Codeforces Round 861 (Div. 2)
    CodeforcesRound861(Div.2)C题直接数位dp即可#include<cstdio>#include<algorithm>#include<cstring>#include<map>#include<queue>#include<bitset>#include<cmath>#include<set>#include<unordered_map>#def......
  • Codeforces Round 920 (Div. 3)
    CodeforcesRound920(Div.3)A-Square#include<bits/stdc++.h>#defineendl'\n'#defineintlonglongusingnamespacestd;constintN=5e5+10;voidsolve(){ map<int,int>x; map<int,int>y; ......
  • Codeforces Round 920 (Div. 3)
    目录写在前面ABCDEFG写在最后写在前面比赛地址:https://codeforces.com/contest/1921写完C题去泡了个面边吃边看D,吃着吃着不对劲味儿怎么这么冲一看过期两个月了我草以及div3都AK不了了呃呃博弈论把我鲨了还剩最后一门近代史,周四才考,开摆!感觉除了离散可能有点拉其他都......
  • Codeforces Round 920 (Div. 3)
    基本情况A、C秒的很快。B、D都错了一发才过。E博弈论属于是短板。E.EattheChipProblem-E-Codeforces首先考虑谁可能赢。因为\(Alice\)只能向下,\(Bob\)只能向上,而\(Alice\)先手。显然两者行差为奇数时\(Alice\)有可能赢,偶数时\(Bob\)有可能赢。再考虑平......
  • Codeforces Round 920 (Div. 3) D Very Different Array
    DVeryDifferentArray题意给出两个长度分别为\(n,m\)的数组\(a,c\),\(n<m\),从\(c\)中选择\(n\)个数并找到一个序列使得\(D=\sum_{i=1}^{n}|a_i-c_i|\)尽可能大,求D的值思路假设如果\(m\)和\(n\)一样大,那么找到这个序列的方法很简单:将两个序列分别排序后将其中一个转置,......
  • hey_left 3 Codeforces Round 918 (Div. 4) 再续
    题目链接F.找了些题解,但都看的不是很懂先去又梳理了一遍堆优化版的dij每次用当前可到达的最小的边去进行松弛操作标记数组,若该点已经加入确定点集,就跳过别忘了dist[]数组初始化为无穷大,这样才会全部都被更新#definelllonglongconstintinf=0x3f3f3f3f;constintN=1e......
  • abc336 E - Digit Sum Divisible 题解 数位DP
    题目链接:https://atcoder.jp/contests/abc336/tasks/abc336_e题目大意:我们定义一个整数\(n\)的数位和为\(n\)的十进制表示中的各位上的数字之和。比如:整数\(2024\)的数位和为\(2+0+2+4=8\)。一个正整数\(n\)被称作一个好数如果\(n\)能被它的数位和整除......
  • CF1818B ndivisible 题解
    题意简述构造一个长度为\(n\)的排列\(A\),使得对于任意的\(l,r\)(\(1\lel<r\len\))都满足\(A_l+A_{l+1}+⋯+A_r\)不可以被\(r-l+1\)整除。输出其中一种合法排列即可。解题思路构造题。考虑对\(n\)进行分类讨论:当\(n=1\)时,由样例即可得合法排列为\(1\)......
  • hey_left 2 Codeforces Round 918 (Div. 4) 续
    题目链接F.常规的树状数组求逆序对需要注意的是,因为是下标与值的映射,所以数值不能为负数,也不能太大然后传参数的时候,参数是最大数值切记切记#include<bits/stdc++.h>usingnamespacestd;constintN=2e5+10;template<typenameT>structTreeArray{vector<T>t......
  • Codeforces Round 919 (Div. 2)(A~D) 题解
    CodeforcesRound919(Div.2)(A~D)题解A.SatisfyingConstraints题意:给你一些条件让你求出满足条件的整数有多少个。模拟即可。#include<bits/stdc++.h>usingnamespacestd;typedeflonglongll;constllMAXN=2e5+5;llTex=1,n;voidAC(){ cin>>n; lll=......