首页 > 其他分享 >The 2022 ICPC Asia Shenyang Regional Contest

The 2022 ICPC Asia Shenyang Regional Contest

时间:2023-10-01 19:23:10浏览次数:42  
标签:cnt Regional Contest int vi Shenyang ++ auto using

C. Clamped Sequence

因为\(n\)的范围不大,并且可以猜到\(l,r\)中应该至少有一个在\(a_i,a_i-1,a_i+1\)上。所以直接暴力枚举\(l\)或\(r\)然后暴力的计算一下

#include <bits/stdc++.h>

using namespace std;

#define int long long

using vi = vector<int>;


int32_t main() {
    ios::sync_with_stdio(false), cin.tie(nullptr);
    int n, d, res = 0;
    cin >> n >> d;
    vector<int> a(n), b;
    for (int &i: a)
        cin >> i, b.push_back(i), b.push_back(i - 1), b.push_back(i + 1);
    sort(b.begin(), b.end());
    b.resize(unique(b.begin(), b.end()) - b.begin());
    for (int r; int l: b) {
        r = l + d;
        auto c = a;
        for (auto &i: c) {
            if (i < l) i = l;
            if (i > r) i = r;
        }
        int cnt = 0;
        for (int i = 1; i < n; i++)
            cnt += abs(c[i] - c[i - 1]);
        res = max(res, cnt);
    }
    for (int l; int r: b) {
        l = r - d;
        auto c = a;
        for (auto &i: c) {
            if (i < l) i = l;
            if (i > r) i = r;
        }
        int cnt = 0;
        for (int i = 1; i < n; i++)
            cnt += abs(c[i] - c[i - 1]);
        res = max(res, cnt);
    }
    cout << res << "\n";
    return 0;
}

D. DRX vs. T1

签到

#include <bits/stdc++.h>

using namespace std;

#define int long long


int32_t main() {
    ios::sync_with_stdio(false), cin.tie(nullptr);
    string s;
    cin >> s;
    map<char,int> cnt;
    for( auto i : s )
        cnt[i] ++;
    if( cnt['T'] >= 3 ) cout << "T1\n";
    else if( cnt['D'] >= 3) cout << "DRX\n";
    return 0;
}

F. Half Mixed

#include <bits/stdc++.h>

using namespace std;

#define int long long

using vi = vector<int>;

void solve() {
    int n, m;
    cin >> n >> m;
    if ((n * (n + 1) * m * (m + 1) / 4) & 1) {
        cout << "No\n";
        return;
    }
    cout << "Yes\n";
    int t = n, T = n * (n + 1) / 2;
    if (T & 1) t = m, T = m * (m + 1) / 2;
    T = T / 2 - t;
    auto f = [&t, &T]() {
        int l = 1, r = t, res = -1;
        for (int mid; l <= r;) {
            mid = (l + r) / 2;
            if (mid * (mid - 1) / 2 <= T) res = mid, l = mid + 1;
            else r = mid - 1;
        }
        t -= res, T -= res * (res - 1) / 2;
        return res;
    };
    vector<int> res;
    for (int x = 0, y; t; x ^= 1) {
        y = f();
        for (; y; y--) res.push_back(x);
    }
    if (res.size() == m) {
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++)
                cout << res[j] << " ";
            cout << "\n";
        }
    } else {
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                cout << res[i] << " ";
            }
            cout << "\n";
        }
    }
    return;
}

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

L. Tavern Chess

直接根据题意模拟,模拟的形式就是用 dfs 去搜索,在搜索的过程中计算出到当前状态的概率。

When a team takes the attack, the leftmost minion with the mininum number of taking attacks from the team attacks one of the alive minios from the other team uniformyly ad random, and then the other team takes the attack.

这句话,在赛时卡了很久,我认为其正确的意思应该是:当一个队伍攻击时,发起攻击次数最少且最靠左的士兵会等概率的随机攻击另一方一个存活的士兵,在攻击后交换攻击。

#include <bits/stdc++.h>

using namespace std;

using vi = vector<int>;
using db = long double;

int n, m;
vi atk0, atk1;
db A = 0, B = 0, T = 0;

void dfs(vi hp0, vi hp1, vi cnt0, vi cnt1, int t, db p, int dep) {

    db alive0 = 0, alive1 = 0; // 存活人数
    for (auto i: hp0) alive0 += (i > 0);
    for (auto i: hp1) alive1 += (i > 0);


    if (alive0 == 0 or alive1 == 0) { // 游戏结束
        if (alive0 == alive1) T += p;
        else if (alive0 == 0) B += p;
        else A += p;
        return;
    }


    if (t == 0) { // Alice attack
        int id = -1;
        for (int i = 0; i < n; i++) {
            if (hp0[i] <= 0) continue;
            if (id == -1 or cnt0[id] > cnt0[i]) id = i;
        }
        cnt0[id]++;

        for (int i = 0; i < m; i++) {
            if (hp1[i] <= 0) continue;
            hp0[id] -= atk1[i], hp1[i] -= atk0[id];
            dfs(hp0, hp1, cnt0, cnt1, t ^ 1, p / alive1, dep + 1);
            hp0[id] += atk1[i], hp1[i] += atk0[id];
        }
    } else { // Bob attack
        int id = -1;
        for (int i = 0; i < m; i++) {
            if (hp1[i] <= 0) continue;
            if (id == -1 or cnt1[id] > cnt1[i]) id = i;
        }
        cnt1[id]++;
        for (int i = 0; i < n; i++) {
            if (hp0[i] <= 0) continue;
            hp0[i] -= atk1[id], hp1[id] -= atk0[i];
            dfs(hp0, hp1, cnt0, cnt1, t ^ 1, p / alive0, dep + 1);
            hp0[i] += atk1[id], hp1[id] += atk0[i];
        }
    }
    return;
}


int32_t main() {
    ios::sync_with_stdio(false), cin.tie(nullptr);
    cin >> n >> m;
    atk0 = vi(n), atk1 = vi(m);
    for (auto &i: atk0) cin >> i;
    for (auto &i: atk1) cin >> i;
    if (n > m) dfs(atk0, atk1, vi(n), vi(m), 0, 1.0, 0);
    else if (m > n) dfs(atk0, atk1, vi(n), vi(m), 1, 1.0, 0);
    else dfs(atk0, atk1, vi(n), vi(m), 0, 0.5, 0), dfs(atk0, atk1, vi(n), vi(m), 1, 0.5, 0);

    cout << fixed << setprecision(10) << A << "\n" << B << "\n" << T << "\n";
    return 0;
}

标签:cnt,Regional,Contest,int,vi,Shenyang,++,auto,using
From: https://www.cnblogs.com/PHarr/p/17739152.html

相关文章

  • AtCoder Beginner Contest 322
    A-FirstABC2解题思路签到Code#include<bits/stdc++.h>usingnamespacestd;typedeflonglongLL;voidsolve(){ intn; cin>>n; strings; cin>>s; intp=s.find("ABC"); if(p==-1)cout<<p<<'\n&......
  • 2022 China Collegiate Programming Contest (CCPC) Guangzhou Onsite
    Preface好难啊这场广州站,不愧是5题金4题铜的超恶劣站,中档题普遍难度较高但我感觉主要原因还是题目出的太偏向于DP了,AI是本质差不多的树上换根DP,M又是个数位DP,导致像我这种不擅长DP的人直接中期坐牢但好在祁神大力切出了medium~hard的K题,然后最后一小时我把一直在想的A题丢给徐......
  • The 2022 ICPC Asia Xi'an Regional Contest
    C.CloneRanran最优解一定是先复制,在做题。最多只需要复制大约30次,直接枚举即可#include<bits/stdc++.h>usingnamespacestd;#defineintlonglonginta,b,c;voidsolve(){cin>>a>>b>>c;intres=LLONG_MAX;for(inti=0,t=1;i......
  • 2022 China Collegiate Programming Contest (CCPC) Mianyang Onsite
    Preface久违地VP一场,由于CCPC桂林在即因此最近就自主VP一下去年的CCPC这场打的时候全队不在状态,签完到后我就因为A题一个cornercase没考虑到卡了快两个小时然后好不容易搞过去徐神上来有狂WAE题,最后也是喜提+11后面写的D题也是需要特判,好家伙又是快到比赛结束才看出来最后......
  • Gym 104270 The 2018 ICPC Asia Qingdao Regional Programming Contest (The 1st Univ
    A.SequenceandSequenceB.KawaExam可以发现,对答案会产生影响的只有割边,把所有边双缩起来,然后就是一个森林。考虑一个树的时候怎么做,就是对于每条边求出这条边两端的众数个数,考虑线段树合并,每次动态维护子树内的众数和子树外的众数。#include<iostream>#include<cstdio>......
  • AtCoder Regular Contest 123 F Insert Addition
    洛谷传送门AtCoder传送门用\((x,y)\)表示\(Ax+By\),那么这个等价于SB树。那么直接在SB树上二分,遍历一遍找到\(n\)个点就好了。可以采用类似线段树查询的方式。于是现在还剩下一个子问题:给定\(a,b\),求\(ax+by\len\)且\(\gcd(x,y)=1\)的正整数\((x,y......
  • 2022 China Collegiate Programming Contest (CCPC) Mianyang Onsite GCHMAD
    2022ChinaCollegiateProgrammingContest(CCPC)MianyangOnsite目录2022ChinaCollegiateProgrammingContest(CCPC)MianyangOnsiteVP情况G-LetThemEatCakeC-CatchYouCatchMeH-LifeisHardandUndecidable,but...M-Rock-Paper-ScissorsPyramidA-......
  • The 2021 China Collegiate Programming Contest (Harbin) JBEIDG
    The2021ChinaCollegiateProgrammingContest(Harbin)目录The2021ChinaCollegiateProgrammingContest(Harbin)VP概况J-LocalMinimumB-MagicalSubsequenceE-PowerandModuloI-PowerandZeroD-MathmasterG-DamagedBicycleVP概况队友不应该写签到,签到......
  • AtCoder Regular Contest 127 F ±AB
    洛谷传送门AtCoder传送门非常妙的题。先直观感受一下,显然当\(M\)大到一定程度后,\([0,M]\)的所有数都能被取到。考虑\(V\getsV+Ax+By\),其中\(V+Ax+By\in[0,M]\)。如果\(x,y\)都是正数显然可以取到。如果一正一负,比如\(x>0,y\le0\),那可以先把\(V\)......
  • KEYENCE Programming Contest 2019
    A-Beginning排序以后判断一下是否为\(1,4,7,9\)即可。#include<iostream>#include<cstdio>#include<algorithm>usingnamespacestd;constintN=10;inta[N];intmain(){ for(inti=1;i<=4;i++) scanf("%d",&a[i]); sort(a+1,a+4+1......