首页 > 其他分享 >2021-2022 ICPC Northwestern European Regional Programming Contest (NWERC 2021)

2021-2022 ICPC Northwestern European Regional Programming Contest (NWERC 2021)

时间:2023-09-22 11:44:36浏览次数:46  
标签:Northwestern ch Contest int res cin mp using 2021

A. Access Denied

先问若干次,问出长度,然后再一位一位的问即可。

#include <bits/stdc++.h>

using namespace std;

int input() {
    string s;
    getline(cin, s);
    if (s == "ACCESS GRANTED")
        exit(0);
    int t = 0;
    for (auto i: s) {
        if (i >= '0' and i <= '9')
            t = t * 10 + i - '0';
    }
    return t;
}

int32_t main() {
    int len = -1;
    for (int i = 1, t; len == -1 and i <= 20; i++) {
        cout << string(i, '0') << endl << flush;
        t = input();
        if (t != 5) len = i;
    }
    vector<char> ans(len), ch;
    for (char i = '0'; i <= '9'; i++) ch.push_back(i);
    for (auto i = 'a'; i <= 'z'; i++) ch.push_back(i);
    for (auto i = 'A'; i <= 'Z'; i++) ch.push_back(i);

    for (int i = 0, t; i < len; i++) {
        for (auto c: ch) {
            for (int j = 0; j < i; j++)
                cout << ans[j];
            for (int j = i; j < len; j++)
                cout << c;
            cout << endl << flush;
            t = input();
            if (t == 5 + (i + 1) * 9) continue;
            ans[i] = c;
            break;
        }
    }
    for( auto i : ans )
        cout << i;
    cout << endl << flush;
    return 0;
}

D. Dyson Circle

首先按照题目的要求,我们可以把戴森环的凹陷部分展开,这样的戴森环就变成了一个矩形。那么对于矩形,我们让边全部在对角线方向最优,所以就要找到主副对角线的边界。如果某对角线方向长度只有 1 的话不符合题目的要求,因为题目要求内点的连通是有边相邻。

#include<bits/stdc++.h>

using namespace std;


int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int n, a = INT_MIN, b = INT_MIN, c = INT_MAX, d = INT_MAX;
    cin >> n;
    if (n == 1) cout << "4\n", exit(0);
    for (int x, y; n; n--) {
        cin >> x >> y;
        a = max(a, x + y);
        b = max(b, x - y);
        c = min(c, x + y);
        d = min(d, x - y);
    }
    cout << 4 + a + b - c - d + (a == c) + (b == d) << "\n";
    return 0;
}

G. Glossary Arrangement

#include<bits/stdc++.h>

using namespace std;

using vi = vector<int>;

int main() {
    ios::sync_with_stdio(0), cin.tie(0);
    int n, w;
    cin >> n >> w;
    vector<string> s(n);
    for (auto &i: s) cin >> i;
    vector<int> f(n + 1);

    auto dp = [n, w, s, &f](int h) {
        f.assign(n + 1, w + 1);
        f[0] = -1;
        for (int i = 0, mx; i < n; i++) {
            mx = 0;
            for (int j = i; j < n and j < i + h; j++) {
                mx = max(mx, int(s[j].size()));
                f[j + 1] = min(f[j + 1], f[i] + mx + 1);
            }
        }
        return f[n];
    };

    int l = 1, r = n, h = -1;
    for (int mid; l <= r;) {
        mid = (l + r) / 2;
        if (dp(mid) <= w) h = mid, r = mid - 1;
        else l = mid + 1;
    }
    cout << h << " ";
    vi v;
    dp(h);
    for (int i = n, j, mx; i;) {
        j = i, mx = 0;
        do {
            j--;
            mx = max(mx, int(s[j].size()));
        } while (f[i] != f[j] + mx + 1);
        v.push_back(mx), i = j;
    }
    reverse(v.begin(), v.end());
    cout << v.size() << "\n";
    for (auto i: v) cout << i << " ";
    cout << "\n";
    vector<string> res(h);
    for (int i = 0, k = 0; i < v.size(); i++) {
        for (int j = 0; j < h; j++) {
            if (i) res[j] += " ";
            string t;
            if (k < n and s[k].size() <= v[i]) t = s[k++];
            t.resize(v[i], ' ');
            res[j] += t;
        }
    }
    for (auto i: res)
        cout << i << "\n";
    return 0;
}

H. Heating Up

初始的辣度满足单调性,因此我们可以用二分答案。

有了初始辣度后,要考虑的就是如何把所有的披萨吃完,首先破环成链,然后从头开始枚举,如果可以吃就直接吃,否则就把这片披萨放进栈里,并且还原耐辣值。同时每次耐辣值上升后,都重新判断一下栈顶的披萨是否可以被吃下。

#include <bits/stdc++.h>

using namespace std;

#define int __int128
using ll = long long;
using pii = pair<int, int>;

int read() {
    int x = 0, f = 1, ch = getchar();
    while ((ch < '0' || ch > '9') && ch != '-') ch = getchar();
    if (ch == '-') f = -1, ch = getchar();
    while (ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + ch - '0', ch = getchar();
    return x * f;
}

constexpr int inf = 1e15;

int32_t main() {
    int n = read();
    vector<int> a(n + n + 1);
    for (int i = 1; i <= n; i++)
        a[i + n] = a[i] = read();
    n = n * 2;
    auto check = [a, n](int x) -> bool {
        int tot = x;
        stack<pii> stk;
        for (int i = 1; i <= n; i++) {
            if (a[i] <= tot) {
                tot += a[i];
                while (!stk.empty() and stk.top().first <= tot) {
                    tot += stk.top().second;
                    stk.pop();
                }
            } else {
                stk.emplace(a[i], tot - x + a[i]);
                tot = x;
            }
        }
        return stk.empty();
    };

    int l = 0, r = inf, res = -1;
    for (int mid; l <= r;) {
        mid = (l + r) / 2;
        if (check(mid)) res = mid, r = mid - 1;
        else l = mid + 1;
    }
    cout << (ll) res << "\n";
    return 0;
}

J. Jet Set

维度是没有用的。

如果在单次飞行中跨过的180 度,则一定是可行的。

否则,根据题目的要求,飞行过程中经过的经度实际上是确定的。我们只要标记即可。

最后判断有无没有被标记的点的即可。

#include <bits/stdc++.h>

using namespace std;


int32_t main() {
    int n;
    cin >> n;
    vector<int> a(n + 2), v(720);
    for (int i = 1, x; i <= n; i++) {
        cin >> x >> a[i];
        a[i] = (a[i] + 180) * 2;
    }
    a[n+1] = a[1];
    for (int i = 2, x, y; i <= n+1; i++) {
        x = a[i - 1], y = a[i];
        if (x > y) swap(x, y);
        if (y - x == 360) cout << "yes\n", exit(0);
        if (y - x < 360) {
            for (int j = x; j <= y; j++) v[j] = 1;
        } else {
            for (int j = 0; j <= x; j++) v[j] = 1;
            for (int j = y; j < 720; j++) v[j] = 1;
        }
    }
    for( int i = 0 ; i < 720 ; i ++ )
        if( v[i] == 0 ) cout << "no " << fixed << setprecision(1) << (0.5*i) - 180.0 << "\n", exit(0);
    cout << "yes\n";

    return 0;
}

K. Knitpicking

我们先尽可能的按照无法配对的情况去选择,最后在任意选一个即可配对,除非已经把所有的袜子全部选完。

如果袜子是任意的,则只有当无左无右的情况下,才能选择一个。否则要选择左右的较大值。

#include<bits/stdc++.h>

using namespace std;
#define pii pair<int, int>
typedef long long ll;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const double pi = acos(-1);
const int N = 110;

void solve() {
    int n;
    cin >> n;
    map<string, array<int, 3> > mp;
    int z = 0;
    for (int i = 0; i < n; ++i) {
        string a, b;
        int x;
        cin >> a >> b >> x;

        if (b == "left") {
            mp[a][0] += x;
        } else if (b == "right") {
            mp[a][1] += x;
        } else {
            mp[a][2] += x;
        }
    }

    int res = 0, mark = 0;
    for (auto X: mp) {
        string a = X.first;
        z += mp[a][0] + mp[a][1] + mp[a][2];

        if (mp[a][0] == 0 && mp[a][1] == 0 && mp[a][2] > 0) res += 1;
        else res += max(mp[a][0], mp[a][1]);
    }

    if (res != z) {
        cout << res + 1 << '\n';
    } else cout << "impossible\n";

}

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int _ = 1;
    while (_--) {
        solve();
    }
    return 0;
}

标签:Northwestern,ch,Contest,int,res,cin,mp,using,2021
From: https://www.cnblogs.com/PHarr/p/17721951.html

相关文章

  • [CSP-J 2021] 插入排序
    题目描述插入排序是一种非常常见且简单的排序算法。小Z是一名大一的新生,今天H老师刚刚在上课的时候讲了插入排序算法。假设比较两个元素的时间为\(\mathcalO(1)\),则插入排序可以以\(\mathcalO(n^2)\)的时间复杂度完成长度为\(n\)的数组的排序。不妨假设这\(n\)个数......
  • The 2021 China Collegiate Programming Contest (Harbin) JBEID
    The2021ChinaCollegiateProgrammingContest(Harbin)JBEIDJ.LocalMinimum模拟题意:一个数当且仅当它是当前列最小值同时也是当且行的最小值它才算入贡献。思路:直接\(for\),预处理出每一行每一列的最小值,然后去\(check\)每一个数。//AConemoretimes//nndbk#inc......
  • 【枚举】【贪心技巧】【集训队互测2021】子集匹配
    题目描述给定\(n,k(2k\geqn)\),二进制中有\(k\)个\(1\)的不超过\(n\)位的数有\(\binom{n}{k}\)个,有\(k-1\)个\(1\)的有\(\binomn{k-1}\)个,后者显然大于等于前者,要求对于每一个\(k\)个\(1\)的数\(x\),都找出一个\(k-1\)位的数\(y\)与之对应,且\(x......
  • AtCoder Beginner Contest 313 Ex Group Photo
    洛谷传送门AtCoder传送门考虑若重排好了\(a\),如何判断可不可行。显然只用把\(b\)排序,把\(\min(a_{i-1},a_i)\)也排序(定义\(a_0=a_{n+1}=+\infty\)),按顺序逐个判断是否大于即可。这启示我们将\(\min(a_{i-1},a_i)\)排序考虑。考虑从大到小加入\(a_i\),那么......
  • 2019, XII Samara Regional Intercollegiate Programming Contest
    \(ProblemA.RoomsandPassages\)倒着处理每个位置正数的最前部的位置。如果是正数,显然答案为后一个位置的答案\(+1\)。如果是负数且前面出现过相应的正数,答案要对这个区间长度\(-1\)的取\(min\)。voidsolve(){intn=read();vector<int>a(n+2),cnt(n+2,-1)......
  • AtCoder Grand Contest 017
    链接C.SnukeandSpells容易发现合法序列排序后一定是若干段值域连续的部分组成:可以发现最小次数就是重叠/空出的部分大小。每次修改只会对\(O(1)\)个点\(±1\),直接维护即可。#include<iostream>#include<cstdio>#include<cstring>#include<vector>#defineN200010......
  • 揭秘ES2021令人兴奋的语言特性
    大家好!我是星辰编程理财。今天我分享一篇关于ES2021(ES12)的文章,它将介绍ES2021的语言特性和功能,包括WeakRefs、Logicalassignmentoperators、Privatemethodsandaccessors(classfields)、Promise.allSettled()等等。通过故事形式以及详细的阐述和示例,带领大家一起探索这些特性......
  • 揭秘ES2021令人兴奋的语言特性
    大家好!我是星辰编程理财。今天我分享一篇关于ES2021(ES12)的文章,它将介绍ES2021的语言特性和功能,包括WeakRefs、Logicalassignmentoperators、Privatemethodsandaccessors(classfields)、Promise.allSettled()等等。通过故事形式以及详细的阐述和示例,带领大家一起探索这些特......
  • The 2023 ICPC Asia Regionals Online Contest (1)
    Preface这场打的还行,因为学长们都没发挥好被我们队偷了,但感觉发挥的也一般前期开题顺序有点问题导致罚时很高,不过中期写题还是很顺的基本都是一遍过只不过在3h的时候过完F到达8题后就开始坐牢了,虽然这场有两个字符串但徐神把H想复杂了,B可以说前面的建SAM和反串的AC自动机都想到......
  • AtCoder Grand Contest 023 E Inversions
    洛谷传送门AtCoder传送门首先将\(a\)从小到大排序,设\(p_i\)为排序后的\(a_i\)位于原序列第\(p_i\)个位置,\(x_i\)为要填的排列的第\(i\)个数。设\(A=\prod\limits_{i=1}^n(a_i-i+1)\),则\(A\)为排列的总方案数(考虑按\(a_i\)从小到大填即得)。套路地,统......