首页 > 其他分享 >Codeforces Round 935 (Div. 3)

Codeforces Round 935 (Div. 3)

时间:2024-03-21 22:04:17浏览次数:18  
标签:int vi Codeforces i64 solve using Div TC 935

A. Setting up Camp

#include <bits/stdc++.h>

using namespace std;

using i32 = int32_t;

void solve() {
    int a, b, c;
    cin >> a >> b >> c;
    int res = a + b / 3;
    b %= 3;
    if (b != 0) {
        if (c < 3 - b) {
            cout << "-1\n";
            return;
        }
        c -= 3 - b, res++;
    }
    res += ( c + 2 ) / 3 ;
    cout << res << "\n";
    return;
}


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

B. Fireworks

计算出每种烟花同时最多看多少个,然后相加即可。

#include <bits/stdc++.h>

using namespace std;

using i32 = int32_t;
using i64 = int64_t;

void solve() {
    i64 a, b, c;
    cin >> a >> b >> c , c ++;
    a = ( c + a - 1 ) / a;
    b = ( c + b - 1 ) / b;
    cout << a + b << "\n";
    return;
}


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

C. Left and Right Houses

可以直接枚举一下路的位置,然后后缀和处理一下。

#include <bits/stdc++.h>

using namespace std;

using i32 = int32_t;
using i64 = int64_t;

void solve() {
    int n;
    string s;
    cin >> n >> s;
    int l = 0, r = 0, ans;
    double p = 1e9;
    for (auto i: s) r += i == '1';
    for (int i = 0; i <= n; i++) {
        if (l >= (i + 1) / 2 and r >= (n - i + 1) / 2) {
            double t = abs(0.5 * n - i);
            if (p > t) p = t, ans = i;
        }
        if( i < n ) l += s[i] == '0' , r-= s[i] == '1';
    }
    cout << ans << "\n";
    return;
}


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

D. Seraphim the Owl

首先我们要从前\(m\)个位置选择一个点作为终点,然后从起点到终点的过程中每个点可以任意选\(a,b\)但是终点只能是\(a\)。

为什么过程中可以任意选\(a,b\),对于每个点,如果你直接走过去就是\(b\),如果停留一下就是\(a\)。

#include <bits/stdc++.h>

using namespace std;

using i32 = int32_t;
using i64 = int64_t;

using vi = vector<i64>;
const i64 inf = 1e18;


void solve() {
    int n, m;
    cin >> n >> m;
    vi a(n + 1), b(n + 2);
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    for (int i = 1; i <= n; i++)
        cin >> b[i], b[i] = min(b[i], a[i]);
    for (int i = n - 1; i >= 1; i--)
        b[i] += b[i + 1];
    i64 res = inf;
    for (int i = 1; i <= m; i++)
        res = min(res, a[i] + b[i + 1]);
    cout << res << "\n";
    return;
}


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

E. Binary Search

我感觉是可以只通过一次操作就一定可以实现要求。

根据这个猜想,交换的一个点应该是目标数字,所以我枚举另一个点,然后进行交换,最后再模仿题目的二分进行一次 check

#include <bits/stdc++.h>

using namespace std;

using i32 = int32_t;
using i64 = long long;
using ui64 = uint64_t;

#define int long long

using vi = vector<int>;
using pii = pair<int, int>;

const int mod = 998244353;
const int inf = 1e18;

const vi dx = {0, 0, 1, -1, 1, 1, -1, -1}, dy = {1, -1, 0, 0, 1, -1, 1, -1};

void solve() {
    int n, x;
    cin >> n >> x;
    vi p(n + 1);
    int y;
    for (int i = 1; i <= n; i++) {
        cin >> p[i];
        if (p[i] == x) y = i;
    }
    for (int i = 1, l, r; i <= n; i++) {
        swap(p[i], p[y]);
        l = 1, r = n + 1;

        for (int m; r - l != 1;) {
            m = (l + r) / 2;
            if (p[m] <= x) l = m;
            else r = m;
        }
        if (p[l] == x) {
            cout << "1\n" << y << " " << i << "\n";
            return;
        }
        swap(p[i], p[y]);
    }
    return;
}

i32 main() {
    ios::sync_with_stdio(false), cin.tie(nullptr);
    int t;
    cin >> t;
    while (t--)
        solve();
    return 0;
}

F. Kirill and Mushrooms

强度等于\(k\times val\),其中\(k\)是我选择的个数,\(val\)是选择的最小值。

如果我枚举出\(k\)就可以确定那些蘑菇的值为 0,然后在剩下的蘑菇中贪心的选择最大的\(k\)个,这样就可以知道\(val\)

我用multiset<int>维护两个集合,一个是cnt表示当前不为0 且没有被选到的蘑菇,q是当前被选到的最大的\(k\)个蘑菇。

然后从小到大枚举\(k\),每次都从\(cnt\)中取最大值填入到q中,直到q.size() == k。然后随着选择数量增大,就要是的一些蘑菇变为0,也就说要从两个集合中删掉一些蘑菇,每次删除时优先从cnt中删除即可。

#include <bits/stdc++.h>

using namespace std;

using i32 = int32_t;
using i64 = long long;
using ui64 = uint64_t;

#define int long long

using vi = vector<int>;
using pii = pair<int, int>;

const int mod = 998244353;
const int inf = 1e18;

void solve() {
    int n;
    cin >> n;
    multiset<int> cnt, q;
    vi a(n + 1);
    vi p(n + 1);
    for (int i = 1; i <= n; i++)
        cin >> a[i], q.insert(a[i]);

    for (int i = 1; i <= n; i++)
        cin >> p[i];
    int res = -inf, val = -inf;
    for (int i = 1, v, x; i <= n; i++) {
        while (not q.empty() and cnt.size() < i) {
            x = *q.rbegin();
            cnt.insert(x), q.erase(q.find(x));
        }
        if (cnt.size() < i) break;
        v = *cnt.begin() * i;
        if (v > res) res = v, val = i;
        
        if (q.count(a[p[i]]))
            q.erase(q.find(a[p[i]]));
        else
            cnt.erase(cnt.find(a[p[i]]));
    }
    cout << res << " " << val << "\n";
    return;
}

i32 main() {
    ios::sync_with_stdio(false), cin.tie(nullptr);
    int t;
    cin >> t;
    while (t--)
        solve();
    return 0;
}

G. Cook and Porridge

这个题目实际上要求维护一个序列,但是这个序列要实现一个插队的功能。

如果把重新入队的人单独放在一个优先队列内。然后提前维护一个\(k_i\)的后缀最大值\(suf_i\)

如果没时刻我取出队列的第一个和优先队列中的第一个。然后比较一下后缀最值和优先队列队首权值的大小,如果后缀最值更大说明不会插队到当前的人前面,则队首出队,否则优先队列出队。

#include <bits/stdc++.h>

using namespace std;

using i32 = int32_t;
using i64 = int64_t;


using vi = vector<i64>;
using pii = pair<i64, i64>;

const i64 inf = 1e18;

#define int i64

void solve() {
    int n, d;
    cin >> n >> d;
    vector<pii> a(n);
    for (auto &[k, s]: a) cin >> k >> s;
    vi suf(n + 1);
    for (int i = n - 1; i >= 0; i--)
        suf[i] = max(a[i].first, suf[i + 1]);
    vector<vi> que(d + 1);
    int t = 0;
    set<array<int, 4>> st;
    for (int time = 1; time <= d; time++) {
        if (not st.empty() and prev(st.end())->at(0) > suf[t]) {
            auto [k, tim, s, id] = *prev(st.end());
            s = -s;
            st.erase(prev(st.end()));
            if (time + s <= d)
                que[time + s].push_back(id);
        } else {
            auto [kt, st] = a[t];
            if (time + st <= d)
                que[time + st].push_back(t);
            t++;
        }
        if (t == n) {
            cout << time << "\n";
            return;
        }
        for (auto id: que[time]) {
            auto [ki, si] = a[id];
            st.insert({ki, -time, -si, id});
        }
    }
    cout << "-1\n";
    return;
}

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

标签:int,vi,Codeforces,i64,solve,using,Div,TC,935
From: https://www.cnblogs.com/PHarr/p/18088311

相关文章

  • 1943+1944.Codeforces Round 934 (Div. 1,Div. 2) - sol
    20240321终于差不多把Div1补完了(F当然没补),第一次打Div1,还是出了一些小状况的。唉。没有补Div1F的逆天题,选择放弃。Dashboard-CodeforcesRound934(Div.2)-CodeforcesDashboard-CodeforcesRound934(Div.1)-Codeforces2A.DestroyingBridgesThere......
  • Educational Codeforces Round 163 (Rated for Div. 2)
    Preface这周很奇怪,连着计网、数据库、组合数学的课都莫名其妙不上了,突然变得很空闲了的说正好有空赶紧补补题,不然接下来有很多造题/比赛的任务搁置着就忘记了A.SpecialCharacters签到,\(n\)是偶数才有解,构造的话注意到一个AAB可以产生\(2\)的贡献,把\(\frac{n}{2}\)个AAB拼起......
  • Tree Compass Codeforces Round 934 (Div. 2) 1944E
    Problem-E-Codeforces题目大意:有一棵n个点的树,初始状态下所有点都是白色的,每次操作可以选择一个点u和一个距离dis,使得距离点u所有长度为dis的点变为黑色,问最少需要多少次操作能使所有点变成黑色,输出所有操作1<=n<=2000思路:要想操作数最少,就要使每次操作涂黑的点的数量尽......
  • HDU 1059 Dividing
    题目传送门:Problem-1059(hdu.edu.cn)问题描述玛莎和比尔拥有一些弹珠。他们希望在自己之间分配收藏品,以便双方都获得平等的弹珠份额。如果所有弹珠都具有相同的价值,这将很容易,因为这样他们就可以将收藏品分成两半。但不幸的是,有些弹珠比其他弹珠更大或更漂亮。因此,Marsha......
  • linux 中shell脚本中遇到 Runtime error (func=(main), adr=22): Divide by zero
    在Linux中编写Shell脚本时,遇到“Runtimeerror(func=(main),adr=22):Dividebyzero”这样的错误通常是因为在脚本中进行了除以零的操作,类似于编程语言中的除零错误。要解决这个问题,您需要检查Shell脚本中涉及到除法运算的地方,确保分母不为零。下面是一个示例S......
  • Codeforces Round 935 (Div. 3) A-G
    A传送门  先考虑无解情况,外在人的数量如果%3之后还剩下x人,只能靠第三类综合性人y来补充进去,如果x+y小于3则无解,有解只需要向上取整即可。#include<bits/stdc++.h>usingll=longlong;typedefstd::pair<int,int>PII;typedefstd::array<int,4>ay;constintN=......
  • codeforce Round 935 div3 个人题解(A-E)
    A.SettingupCamp时间限制:每个测试1秒内存限制:每个测试256兆字节输入:标准输入输出:标准输出组委会计划在游览结束后带领奥林匹克运动会的参赛选手进行徒步旅行。目前,正在计算需要搭帐篷的数量。已知每顶帐篷最多可容纳3人。在参赛选手中,有a个内向型,b个外向型和c个综合型:......
  • CodeForces 1945H GCD is Greater
    洛谷传送门CF传送门感觉是这场唯一比较有趣的题?首先明确一点:先手只会选\(2\)个数,因为数多了\(\gcd\)会变小,而且对方的\(\text{and}\)会变大。所以对于某一位,若\(0\)的个数\(\ge3\)那么对方的按位与这一位一定是\(0\)。所以若\(0\)的个数\(\le2\),那么可能会......
  • Codeforces Round 923 (Div. 3) D. Find the Different Ones!
    写点简单的思维题https://codeforces.com/problemset/problem/1927/D思路:用两个数组,一个存储原始数据,一个用nex存该位置第一次不一样的下标#include<iostream>#include<vector>#include<algorithm>#include<math.h>#include<sstream>#include<string>#include<str......
  • CF1935 A-C题解
    A设\(s\)翻转后的字符串为\(t\),考虑进行\(n\)次操作可能生成出哪些字符串:只进行翻转操作——\(s\);先复制再\(n-1\)次翻转——\(s+t\);先翻转,再复制,再翻转\(n-2\)次,\(t+s\);多次复制的情况。情况2显然劣于情况1;情况4得到的字符串的开头一定是\(s\)或者\(t\)......