首页 > 其他分享 >Codeforces Round 886 (Div. 4)

Codeforces Round 886 (Div. 4)

时间:2023-07-24 19:55:56浏览次数:40  
标签:PII 886 int cin long Codeforces ++ ans Div

Dashboard - Codeforces Round 886 (Div. 4) - Codeforces

A. To My Critics

判断任意两个大于10即可

#include <bits/stdc++.h>
#define int long long

using namespace std;

const int N = 2e5 + 10;

signed main() {

    ios::sync_with_stdio(false);cin.tie(nullptr);

    int a,b,c;
    cin >> a >> b >> c;
    if(a + b >= 10 || b + c >= 10|| a + c >= 10)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;


    return 0;
}

B. Ten Words of Wisdom

把质量大于10的pass掉,剩下的排个序即可

#include <bits/stdc++.h>
#define int long long

using namespace std;

typedef pair<int,int> PII;

signed main() {

    ios::sync_with_stdio(false);cin.tie(nullptr);

    int T;
    cin >> T;
    while(T--){
        int n;
        cin >> n;
        vector<PII> a;
        for(int i = 1, x,y;i <= n;i ++){
            cin >> x >> y ;
            if(x > 10) continue;
            else
                a.emplace_back(i,y);
        }
        sort(a.begin(),a.end(),[](PII x,PII y){
            return x.second > y.second;
        });
        cout << a.front().first << endl;
    }

    return 0;
}

C. Word on the Paper

模拟题,因为它没有逆字符串,所以遇到字符就加上即可

#include <bits/stdc++.h>
#define int long long

using namespace std;

signed main() {

    ios::sync_with_stdio(false);cin.tie(nullptr);

    int T;
    cin >> T;
    while(T--){
        vector<string> g(8);
        for(int i = 0;i < 8;i ++)
            cin >> g[i];

        string ans = "";

        for(int i = 0;i < 8;i ++){
            for(int j = 0;j < 8;j ++){
                if(g[i][j] == '.')
                    continue;
                else
                    ans += g[i][j];
            }
        }

        cout << ans << endl;
    }
    return 0;
}

D. Balanced Round

就是找连续的数的差值在k的范围内的有多少,找到最大的之后其余的数就是至少要删掉的了

#include <bits/stdc++.h>
#define int long long

using namespace std;

typedef pair<int,int> PII;

signed main() {

    ios::sync_with_stdio(false);cin.tie(nullptr);

    int T;
    cin >> T;
    while(T--){
        int n,k;
        cin >> n >> k;
        vector<int> a(n);
        for(auto &i : a) cin >> i;

        sort(a.begin(),a.end());
        int ans = 0, now = 1;
        for(int i = 0;i < n - 1;i ++ ){
            if(a[i + 1] - a[i] <= k){
                now++;
            }else{
                ans = max(now,ans);
                now = 1;
            }
        }
        ans = max(ans, now);
        cout << n - ans << endl;
    }
    return 0;
}

E. Cardboard for Pictures

根据题意就是求\(\sum\limits_{i=1}^{n} (2 \times w + s_i)^2 = C\)这样一个公式中的\(w\)存在的,答案存在递增性,于是我们可以用二分答案来做,每次判断是否符合条件在计算过程中,可能会爆\(long long\),需要开__int128,如果你是只要大于就提前返回的话就不用开,另外因为要开方,所以\(w\)最大只能取\(1e9\).

#include <bits/stdc++.h>
#define int long long

using namespace std;

typedef pair<int,int> PII;

signed main() {

    ios::sync_with_stdio(false);cin.tie(nullptr);

    int T;
    cin >> T;
    while(T--){
        int n,c;
        cin >> n >> c;
        vector<int> s(n);
        for(auto &i : s) cin >> i;

        auto check = [&](int x){
            __int128 ans = 0;
            for(auto i : s){
                ans += ((__int128)2 * x + i) * ((__int128)2 * x + i);
                if(ans > c) return true;
            }
            return ans > c;
        };

        int l = 1, r = 1e9;
        while(l <= r){
            int mid = (l + r) >> 1;
            if(check(mid))
                r = mid - 1;
            else
                l = mid + 1;
        }
        cout << l - 1 << endl;
    }
    return 0;
}

F. We Were Both Children

用一个桶\(s\)去维护每只青蛙能跳到的最大倍数,暴力枚举每个\(a_i\)能贡献到的最大的\(s_j\),即\(j\)是\(a_i\)的倍数,最后在桶里找一个最大值即可\(\mathcal{O}(nlogn)\)

#include <bits/stdc++.h>
#define int long long

using namespace std;

typedef pair<int,int> PII;

signed main() {

    ios::sync_with_stdio(false);cin.tie(nullptr);

    int T;
    cin >> T;
    while(T--){
        int n,c;
        cin >> n ;
        vector<int> s(n + 1);
        for(int i = 0;i < n;i ++) {
            cin >> c;
            if(c <= n)
                s[c] ++;
        }

        for(int i = n;i >= 1; i--){
            for(int j = 2 * i; j <= n;j += i)
                s[j] += s[i];
        }

        cout << *max_element(s.begin(),s.end()) << endl;
    }
    return 0;
}

G. The Morning Star

d4bc950948a1049d2c81071966d4259748cb892a.png (183×182) (codeforces.com)

可以用map来维护四个桶,记录四个方向,另外四个方向都是在同一条直线上,所以我计算出结果后乘2即可,对于\(N,S,x相同,W,E,y相同,NE,SW,x - y相同,SE,NW,x+y相同\),将星星个数全部累加起来即可

#include <bits/stdc++.h>
#define int long long

using namespace std;

typedef pair<int,int> PII;

signed main() {

    ios::sync_with_stdio(false);cin.tie(nullptr);

    int T;
    cin >> T;
    while(T--){
        int n;
        cin >> n;
        map<int,int> mp[4];
        int ans = 0;
        for(int i = 0,x,y;i < n;i ++){
            cin >> x >> y;
            ans += mp[0][x] ++ ;
            ans += mp[1][y] ++ ;
            ans += mp[2][x - y] ++ ;
            ans += mp[3][y + x] ++ ;
        }
        cout << ans * 2 << endl;
    }
    return 0;
}

标签:PII,886,int,cin,long,Codeforces,++,ans,Div
From: https://www.cnblogs.com/Kescholar/p/17578166.html

相关文章

  • 【题解】Ntarsis' Set - Codeforces 1852A
    出处:CodeforcesRound887链接:https://codeforces.com/problemset/problem/1852/A题目大意:给定一个包含\(n\)个正整数的表示删除位置的严格升序序列\(p\),以及另外一个连续正整数的被删除的无穷序列\(l\)。进行\(k\)次删除操作,每次操作从无穷序列\(l\)中同时删除位......
  • Educational Codeforces Round 71
    A.ThereAreTwoTypesOfBurgers#include<bits/stdc++.h>usingnamespacestd;#defineintlonglongvoidsolve(){intb,p,f,h,c;cin>>b>>p>>f>>h>>c;b/=2;intres=0;for(inti......
  • Codeforces Round 887 (Div. 1) 题解
    https://codeforces.com/contest/1852/problemsA.Ntarsis'Sethttps://codeforces.com/contest/1852/problem/A感觉不是很一眼。\(n\)和\(k\)都是\(2\times10^5\),不能暴力,设当前集合为\({1,2,\dots,10^{1000}}\),那么被操作过一次的最小值就应该是\(\text{MEX}(0,......
  • CodeForces 1810G The Maximum Prefix
    洛谷传送门CF传送门感觉是比较educational的题。拿到题目应该有一个大致思路,就是考虑最大前缀和的求法,再把它扔到状态里面。最大前缀和有两种求法:从前往后求,需要维护当前前缀和\(s\),当前最大前缀和\(mx\),需要记录两个变量,无法承受。从后往前求,只需记录当前最大前缀和......
  • 「题解」Codeforces Round 887 (Div. 2)
    A.DesortingProblem题目Sol&Code若序列一开始无序答案为\(0\)若有序即\(a_1\leqa_2\leq\dots\leqa_n\)。若想让\(a_i>a_j(i<j)\),操作次数与两数差值\(d(d=a_j-a_i)\)相关为\(\lfloor\dfrac{d}{2}\rfloor+1\),差值越小操作次数越少,故枚举相邻两数取最少......
  • Codeforces Round 887 (Div. 2)
    C.Ntarsis'Set​ (\(1\leqn,k\leq2\cdot10^5\))题解:思维+二分我们不妨反向考虑由于答案最后一次一定在第一个位置所以答案上一轮一定在第一个空的位置,假设这个位置为\(x\)那么如果说要使得答案在位置\(x\),那么上上一轮答案一定在第\(x\)个空的位置我们可以......
  • Codeforces Round 887 (Div 2) C. Ntarsis' Set
    Ntarsis'Set题意是给你n个数,每次按照顺序删除位于a[i]位置的这n个数,问k次后最小的是多少参考这位大佬的题解CodeforcesRound887(Div2)A~C-知乎(zhihu.com)结合一个官方题解,进行一次操作后,由于前面删掉i个数,a[i]到a[i+1]间所有数的排名都要-=i,那么在a[i]到a[i+1]之间的......
  • 【题解】Educational Codeforces Round 151(CF1845)
    VP战报:1h过了A,B,C,D然后被E罚坐1hrank:210th题解只有A-EA.ForbiddenInteger题目描述:你需要构造一个正整数序列,满足:对于\(i\),\(a_i\lek\)且\(a_i\not=x\)。\(\suma_i=n\)。如无法构造,输出NO,否则输出YES后,输出序列长度与序列中的每一个数。多测\(t\le......
  • Codeforces Round 886 (Div. 4) 题解 A - H
    A.ToMyCritics题目大意给定三个数,你可以挑俩数加起来,问这仨数有没有可能加起来大于等于\(10\).解题思路我们找其中最大的两个数相加与\(10\)比较即可。ACCode#include<iostream>#include<algorithm>#include<cstring>#defineendl'\n'#defineiosios::sync......
  • Codeforces Round 886 (Div. 4) 全题题解
    我关注的人中正式参与比赛排名公示:#Who=Penalty*ABCDEFGH1(980)Chen_Jinhui7381\(\color{#00CC00}{\textbf{+}}\)00:05\(\color{#00CC00}{\textbf{+1}}\)00:17\(\color{#00CC00}{\textbf{+}}\)00:19\(\color{#00CC00}{\textbf{+}}\)01:08......