首页 > 其他分享 >2022-2023 ICPC Central Europe Regional Contest

2022-2023 ICPC Central Europe Regional Contest

时间:2023-10-06 16:44:57浏览次数:45  
标签:Europe Central Contest int dd back que opp op

The 1st Universal Cup. Stage 8: Slovenia

D. Deforestation

这道题出题人比较谜语人,对于一个分叉点,只能选择若干个儿子和父亲组成一组,剩下的儿子之间不能相互组合。所以从叶子节点开始贪心处理就好。对于一个父亲他有若干个儿子,就贪心的选择剩下部分更小的儿子。

#include <bits/stdc++.h>

using namespace std;

#define int long long

using vi = vector<int>;

constexpr int inf = 1E18;


int32_t main() {
    ios::sync_with_stdio(false), cin.tie(nullptr);
    int w;
    cin >> w;
    int res = 0;
    auto dfs = [&](auto &&self) -> int {
        int v, n;
        cin >> v >> n;
        vector<int> t(n);
        for (int x; auto &i: t)
            x = self(self), res += x / w, i = x % w;
        sort(t.begin(), t.end());
        int cnt = 0;
        for (auto i: t) {
            if (cnt + i <= w) cnt += i;
            else res++;
        }
        return v + cnt;
    };
    res += ( dfs(dfs) + w - 1 ) / w;
    cout << res << "\n";
    return 0;
}

E. Denormalization

因为每次除的数字相同,所以数组的比值并不会发生改变,只要先枚举出一个数,然后根据比值算出其他的数,然后验证一下最大公约数就好。但问题是枚举哪一个数呢?我通过罚时试出来枚举最大值,其他值会被卡精度

#include <bits/stdc++.h>

using namespace std;

using ldb = long double;
#define int long long
constexpr ldb eps = 1E-6;


int32_t main() {
    int n;
    cin >> n;
    vector<ldb> a(n);
    for (auto &i: a)
        cin >> i;

    int t = max_element(a.begin(), a.end()) - a.begin();
    for (int i = 0; i < n; i++)
        if( i != t ) a[i] /= a[t];
    a[t] = 1;
    vector<int> b(n);

    for (b[t] = 1; b[t] <= 10000; b[t]++) {
        int d = b[t];
        for (int i = 0; i < n; i++) {
            if (i == t) continue;
            ldb x = (ldb) b[t] * a[i];
            if (x - floor(x) < eps) b[i] = floor(x);
            else if (ceil(x) - x < eps) b[i] = ceil(x);
            else {
                d = -1;
                break;
            }
            d = gcd(d, b[i]);
        }
        if (d != 1) continue;
        for (auto i: b)
            cout << i << "\n";
        return 0;
    }
    return 0;
}

L. The Game

阅读题加模拟题,读懂之后很好写

#include <bits/stdc++.h>

using namespace std;

using vi = vector<int>;

int32_t main() {
    vi pile(98);
    for (auto &i: pile) cin >> i;
    reverse(pile.begin(), pile.end());
    vector<vi> que(4);
    que[0].push_back(1);
    que[1].push_back(1);
    que[2].push_back(100);
    que[3].push_back(100);
    vi hand;
    for (int i = 0; i < 8; i++)
        hand.push_back(pile.back()), pile.pop_back();
    while (true) {
        int op = -1;
        auto it = hand.begin();
        for (; it != hand.end(); it = next(it)) {
            if (que[0].back() > *it and que[0].back() - *it == 10) {
                op = 0;
                break;
            } else if (que[1].back() > *it and que[1].back() - *it == 10) {
                op = 1;
                break;
            } else if (que[2].back() < *it and *it - que[2].back() == 10) {
                op = 2;
                break;
            } else if (que[3].back() < *it and *it - que[3].back() == 10) {
                op = 3;
                break;
            }
        }
        if (op != -1) {
            que[op].push_back(*it);
            hand.erase(it);
        } else {
            it = hand.begin();
            auto jt = it;
            int deta = 1e9;
            for (int dd, opp; it != hand.end(); it = next(it)) {
                dd = 1e9, opp = -1;
                if (que[0].back() < *it and *it - que[0].back() < dd) {
                    dd = *it - que[0].back(), opp = 0;
                }
                if (que[1].back() < *it and *it - que[1].back() < dd) {
                    dd = *it - que[1].back(), opp = 1;
                }
                if (que[2].back() > *it and que[2].back() - *it < dd) {
                    dd = que[2].back() - *it, opp = 2;
                }
                if (que[3].back() > *it and que[3].back() - *it < dd) {
                    dd = que[3].back() - *it, opp = 3;
                }
                if (opp == -1) continue;
                if (dd < deta)
                    deta = dd, jt = it, op = opp;
            }
            if (op == -1) break;
            que[op].push_back(*jt);
            hand.erase(jt);
        }

        // 第二张
        op = -1;
        it = hand.begin();
        for (; it != hand.end(); it = next(it)) {
            if (que[0].back() > *it and que[0].back() - *it == 10) {
                op = 0;
                break;
            } else if (que[1].back() > *it and que[1].back() - *it == 10) {
                op = 1;
                break;
            } else if (que[2].back() < *it and *it - que[2].back() == 10) {
                op = 2;
                break;
            } else if (que[3].back() < *it and *it - que[3].back() == 10) {
                op = 3;
                break;
            }
        }
        if (op != -1) {
            que[op].push_back(*it);
            hand.erase(it);
        } else {
            it = hand.begin();
            auto jt = it;
            int deta = 1e9;
            for (int dd, opp; it != hand.end(); it = next(it)) {
                dd = 1e9, opp = -1;
                if (que[0].back() < *it and *it - que[0].back() < dd) {
                    dd = *it - que[0].back(), opp = 0;
                }
                if (que[1].back() < *it and *it - que[1].back() < dd) {
                    dd = *it - que[1].back(), opp = 1;
                }
                if (que[2].back() > *it and que[2].back() - *it < dd) {
                    dd = que[2].back() - *it, opp = 2;
                }
                if (que[3].back() > *it and que[3].back() - *it < dd) {
                    dd = que[3].back() - *it, opp = 3;
                }
                if (opp == -1) continue;
                if (dd < deta)
                    deta = dd, jt = it, op = opp;
            }
            if (op == -1) break;
            que[op].push_back(*jt);
            hand.erase(jt);
        }


        for (int i = 0; !pile.empty() and i < 2; i++)
            hand.push_back(pile.back()), pile.pop_back();
    }
    for (auto it: que) {
        for (auto i: it)
            cout << i << " ";
        cout << "\n";
    }
    for (auto i: hand)
        cout << i << " ";
    cout << "\n";
    reverse(pile.begin(), pile.end());
    for (auto i: pile)
        cout << i << " ";
    cout << "\n";
    return 0;
}

标签:Europe,Central,Contest,int,dd,back,que,opp,op
From: https://www.cnblogs.com/PHarr/p/17744699.html

相关文章

  • The 2021 ICPC Asia Macau Regional Contest
    A.SoI'llMaxOutMyConstructiveAlgorithmSkills首先一行正一行反的把所有的行拼到一起,然后判断一下正着走时候合法不合法就反过来走就好。#include<bits/stdc++.h>usingnamespacestd;#defineintlonglongusingvi=vector<int>;voidsolve(){intn;......
  • The 2022 ICPC Asia Jinan Regional Contest
    A.Tower首先用了dp验证出把一个数字变成另一个数字的最优解一定是能除就先进行除法,然后再使用加一减一。这样我们就有\(O(\logn)\)的复杂度求出把一个数变成另一个数的最小代价。然后就是猜测最终的目标一定是某个数除了若干次二得到的。所以就枚举一下目标即可。#include......
  • The 2018 ACM-ICPC Asia Qingdao Regional Contest, Online (The 2nd Universal Cup
    The2018ACM-ICPCAsiaQingdaoRegionalContest,Online(The2ndUniversalCup.Stage1:Qingdao)J-PresstheButton\(1\leqa,b,c,d\leq10^6\)题解容易发现存在循环节,每次位于\(gcd(a,c)\)的倍数的位置所以我们考虑处理一个循环节内的情况如果\(v\le......
  • AtCoder Grand Contest 036 F Square Constraints
    洛谷传送门AtCoder传送门本质是\(p_i\in[l_i,r_i]\)的计数问题。当\(1\lei\len\)时,\(l_i\)才可能不等于\(1\)。考虑容斥,设钦定\(m\)个不满足条件(上界为\(l_i-1\)),其余任意(上界为\(r_i\))。然后按照上界排序后dp,设\(f_{i,j}\)为考虑前\(i\)个元素,已经......
  • 2017 China Collegiate Programming Contest Final (CCPC-Final 2017)
    Preface今天打学校统一要求的这场CCPC2017Final,直接被打爆了,各种数学题搞得人生活不能自理主要是H徐神开场就秒出了正确的思路,然后一心认准高斯消元然后一直想+写+调到结束都没卡过去比赛最后20min的时候祁神想到了更好写的基于施密特正交化的方法,可以碍于时间有限没调出来不......
  • AtCoder Beginner Contest 288 Ex A Nameless Counting Problem
    洛谷传送门AtCoder传送门考虑到规定单调不降比较难搞。先设\(g_t\)为长度为\(t\)的满足条件的序列个数(可重且有顺序)。求这个可以设个dp,\(f_{d,i}\)表示考虑到从高到低第\(d\)位,当前\(t\)个数中有\(i\)个仍然顶上界,并且之前的位都满足异或分别等于\(X\)的限制。......
  • AtCoder Grand Contest 056 D Subset Sum Game
    洛谷传送门AtCoder传送门考虑若\(n\)是奇数怎么做。枚举Alice第一次选的数\(a_i\),然后考虑把剩下的数两两结成一个匹配,若Bob选了其中一个,Alice就选另一个。容易发现排序后奇数位和它右边的偶数位匹配最优。那么设奇数位的和为\(A\),偶数位的和为\(B\),此时Alice获胜......
  • AtCoder Beginner Contest 178 E
    AtCoderBeginnerContest178EE-DistMax曼哈顿距离最大点对\(ans=max(|x_i-x_j|+|y_i-y_j|)\)考虑去绝对值,4种情况。sort一下取max即可。#include<bits/stdc++.h>usingnamespacestd;typedeflonglongll;constintN=2e5+10;intx[N],y[N];intp[4][N];......
  • 2022 China Collegiate Programming Contest (CCPC) Weihai Site
    PrefaceVP到自己学校出的题了可海星,不得不说学长们出的题比起昨天VP的CCPC2022广州做起来要舒服地多这场前面写题都很顺基本都是一发过,中期的medium也没怎么卡思路和卡机子,一道一道地慢慢出最后一个小时徐神RushF可惜没Rush出来,然后我和祁神坐在下面把B的做法给搞出来了,但不知......
  • The 2022 ICPC Asia Shenyang Regional Contest
    C.ClampedSequence因为\(n\)的范围不大,并且可以猜到\(l,r\)中应该至少有一个在\(a_i,a_i-1,a_i+1\)上。所以直接暴力枚举\(l\)或\(r\)然后暴力的计算一下#include<bits/stdc++.h>usingnamespacestd;#defineintlonglongusingvi=vector<int>;int32_tmain(){......