首页 > 其他分享 >Codeforces Round 870 (Div. 2)

Codeforces Round 870 (Div. 2)

时间:2023-05-06 21:34:12浏览次数:40  
标签:typedef const int ll Codeforces 870 cin long Div

Codeforces Round 870 (Div. 2)

A - Trust Nobody

思路:枚举每一种说谎人数x,若a[i]大于x则说谎人数加一,判断最后说谎总人数是否为x,若是则输出x,结束枚举;若没有满足的x则-1

#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int>PII;
typedef pair<string,int>PSI;
const int N=2e2+5,INF=0x3f3f3f3f,Mod=1e6;

const double eps=1e-6;
typedef long long ll;

int t,n,a[N];
bool cmp(int x,int y){
    return x>y;
}

int main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    cin>>t;
    while(t--){
        cin>>n;
        for(int i=0;i<n;++i)cin>>a[i];
        bool ok=false;
        for(int i=0;i<=n;++i){
            int c=0;
            for(int j=0;j<n;++j){
                if(a[j]>i)c++;
            }
            if(c==i){
                cout<<i<<'\n';
                ok=true;
                break;
            }
        }
        if(!ok)cout<<-1<<'\n';
    }
    return 0;
}
View Code

 

 B - Lunatic Never Content

思路:若两数分别对x求余后的值相等,则该两数相减后的值一定是x的倍数,对所有对称的数相减后的值求最大公因数即可

#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int>PII;
typedef pair<string,int>PSI;
const int N=1e5+5,INF=0x3f3f3f3f,Mod=1e6;

const double eps=1e-6;
typedef long long ll;

int t,n,a[N];


int main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    cin>>t;
    while(t--){
        cin>>n;
        int res=0;
        for(int i=0;i<n;++i)cin>>a[i];
        if(n!=1){
            for(int i=0;i<n/2;++i){
                if(i==0)res=abs(a[i]-a[n-i-1]);
                else res=__gcd(res,abs(a[i]-a[n-i-1]));
            }
        }
        cout<<res<<'\n';
    }
    return 0;
}
View Code

 

C - Dreaming of Freedom

思路:每种选择的个数相同则是NO,那么就判断是否能让每种选择的个数相同;那就求x的最小的非1因子,若y大于等于该因子则NO;x的范围1e6,可以先处理出所有范围内的数的最小因子

#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int>PII;
typedef pair<string,int>PSI;
const int N=1e6+5,INF=0x3f3f3f3f,Mod=1e6;

const double eps=1e-6;
typedef long long ll;

int t,x,y;
bool st[N];
int primes[N],idx;
void P(){
    st[1]=true;
    for(int i=2;i<=N-5;++i){
        if(!st[i])primes[idx++]=i;
        for(int j=0;primes[j]*i<=N-5;++j){
            st[primes[j]*i]=true;
            if(i%primes[j]==0)break;
        }
    }
}

int main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    cin>>t;
    P();
    while(t--){
        cin>>x>>y;
        bool ok=true;
        if(!st[x]&&y>=x)ok=false;
        if(st[x]){
            for(int i=2;i<=x;++i){
                if(x%i==0){
                    if(y>=i)ok=false;break;
                }
            }
        }
        if(ok)cout<<"YES\n";
        else cout<<"NO\n";
    }
    return 0;
}
View Code

 

D - Running Miles

思路:由于a,b,c是[l,r]中最大的三个数,要使a+b+c-(r-l)最大,对于固定的abc,(r-l)就要最小,假设abc按下标顺序排,那么r对应的是c的下标,l对应的是a的下标;a+b+c-(r-l) = (a+l)+b+(c-r),求出ai+i的最大前缀值和ci-i的最大后缀值,枚举b即可

#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int>PII;
typedef pair<string,int>PSI;
const int N=1e5+5,INF=0x3f3f3f3f,Mod=1e6;

const double eps=1e-6;
typedef long long ll;

ll t,n,b[N],l[N],r[N];

int main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    cin>>t;
    while(t--){
        cin>>n;
        for(int i=1;i<=n;++i){
            cin>>b[i];
            l[i]=max(l[i-1],i+b[i]);
        }
        for(int i=n;i>=1;--i){
            if(i==n)r[i]=b[i]-i;
            else r[i]=max(r[i+1],b[i]-i);
        }
        ll res=-INF;
        for(int i=2;i<=n-1;++i){
            res=max(res,b[i]+l[i-1]+r[i+1]);
        }
        cout<<res<<'\n';
    }
    return 0;
}
View Code

 

标签:typedef,const,int,ll,Codeforces,870,cin,long,Div
From: https://www.cnblogs.com/bible-/p/17378463.html

相关文章

  • Codeforces 1817F - Entangled Substrings(SA)
    为什么赛时不开串串题?为什么赛时不开串串题?为什么赛时不开串串题?为什么赛时不开串串题?为什么赛时不开串串题?一种SA做法,本质上和SAM做法等价,但是说来也丢人,一般要用到SAM的题我都是拿SA过的/wul考虑将\(ac\)看作一个整体。记\(\text{occ}(S)\)为\(S\)出现位置的集......
  • Codeforces Round 848 (Div. 2)C
    B.TheForbiddenPermutation一定要注意题目中说的是对于alli满足才算不好的,我们做的时候只要破坏一个i这个a就不算好的了,被这一点坑了,没注意到all。#include<bits/stdc++.h>usingnamespacestd;typedeflonglongLL;constintN=2e5+10;intp[N],a[N];vo......
  • Codeforces Round 856 (Div. 2)C
    C.ScoringSubsequences思路:我们想要找到满足的最大值的长度最长的的区间,因为单调不减,所以更大的数一定在最大值的里面包含,所以我们用两个指针维护这样一个满足当前i的最大值区间,当新来一个数,这时我们答案里面一定要包含这个数,我们看能否保持这个长度,能不能保持需要看j指针所指......
  • Codeforces——870
    A.TrustNobody题目大意给你一个长度为\(n\)的数组\(a\),\(a\)中每个元素\(a_i\)表示当前人认为\(n\)个人中至少有\(a_i\)个人说谎,让你找出说谎的人的个数。思路:枚举说谎人数\(x\),遍历\(a\)数组,对于当前\(a_i\),如果有\(a_i\geqx\),那么显然第\(i\)个人在说谎,记录人数看是否等......
  • [CodeForces-143A]题解(C++)
    PartIPreface原题目(Luogu)原题目(CodeForces)PartIISketch设有一个\(2\times2\)的棋盘,上面可以填入\(1-9\)的数字。给出\(6\)个数字,为每行每列以及每个对角线上的数字之和,求相应的摆放方式,无解输出\(-1\)。PartIIIAnalysis观察此题数据规模,不难发现数据......
  • [CodeForces-1104A]题解(C++)
    PartIPreface原题目(Luogu)原题目(CodeForces)PartIISketch给定一个整数\(n\)。将\(n\)拆分成一个数列\(a_1,a_2,a_3,\dots,a_m\)。使得\(\sum\limits_{k=1}^{m}a_k=n\),每个\(a_i\in[0,9]\)且数列中不相同的数的数量尽量少。PartIIIAnalysis我们很容易......
  • [CodeForces-545A]题解(C++)
    PartIPreface原题目(Luogu)原题目(CodeForces)PartIISketch给定一个正整数\(n\),表示汽车数量。给定一个\(n\timesn\)阶矩阵\(A\),第\(i\)行\(j\)列上的数字表示\(i\)车与\(j\)车的对撞情况。\(\begin{aligned}\begin{cases}A_{i,j}=-1&i,j\text{车没......
  • [CodeForces-545A]题解(C++)
    PartIPreface原题目(Luogu)原题目(CodeForces)PartIISketch给定一个正整数\(n\),表示汽车数量。给定一个\(n\timesn\)阶矩阵\(A\),第\(i\)行\(j\)列上的数字表示\(i\)车与\(j\)车的对撞情况。\(\begin{aligned}\begin{cases}A_{i,j}=-1&i,j\text{车没......
  • Educational Codeforces Round 147 (Rated for Div. 2) (贪心)
    原题链接:https://codeforces.com/contest/1821/problem/D*题意:从1开始走,走的给定区间的值要k次。且shift按了要松开,代表走了一个区间除了往右的次数,还要多两次按shift的次数,求最小次数。*思路:1.先把不可能的情况列出来,就是给出的区间大小小于k时直接输出-12.我的思路是暴......
  • Codeforces Round 867 (Div. 3)
    A.TubeTubeFeed分析:从所有a[i]+i-1<=t的选择种取个max即可code:#include<bits/stdc++.h>usingnamespacestd;constintN=55;inta[N],b[N];intmain(){std::ios::sync_with_stdio(false);cin.tie(0),cout.tie(0); intt; cin>>t;......