C/C++教程

Codeforces Round #560 (Div. 3)

本文主要是介绍Codeforces Round #560 (Div. 3),对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

Codeforces Round #560 (Div. 3)

A

# include <bits/stdc++.h>
using namespace std; 
​
const int MAXN=2e5+100;
int main()
{
    int n,y,x;
    string a;
    int sum=0;
    scanf("%d %d %d",&n,&y,&x);
​
    cin>>a;
    //cout<<n<<" "<<y<<" "<<x<<endl;
//  for(int i=0;i<n;i++){
//      printf("%c",a[i]);
//  }
//  cout<<endl;
​
//cout<<a[n-2]<<endl;
    if(a[n-1-x]=='0'){
        sum++;
    }
    //cout<<a[n-1-x]<<endl;
    //cout<<sum<<endl;
    for(int i=n-1;i>=(n-y);i--){
        if(i==(n-1-x)) continue;
        else{
            if(a[i]!='0'){
                sum++;
            }
        }
    }
    
    printf("%d",sum);
    
    return 0;
}
​

B

# include <bits/stdc++.h>
using namespace std;
​
const int MAXN=2e5+100;
set<int> a;
int main()
{
    int n;
    
    scanf("%d",&n);
    
    for(int i=1;i<=n;i++){
        int x;
        scanf("%d",&x);
        a.insert(x);
    }
    
    int j=1;
    int flag=1;
    for(set<int>::iterator it=a.begin();it!=a.end();it++){
        //cout<<*it<<" "<<j<<endl;
        if(*it<j){
            j--;
            flag=0;
            break;
        }else{
            j++;
        }
    }
    if(flag){
        j--;
    }
    
    printf("%d",j);
    
    return 0;
}
​

C

# include <bits/stdc++.h>
using namespace std;
​
const int MAXN=2e5+100;
int f[MAXN];
int main()
{
    int n;
    string a;
    int ll;
    
    scanf("%d",&n);
    ll=n;
    cin>>a;
    
    for(int i=0;i<n;){
        if((i+1)>=n) break;
        if(a[i]!=a[i+1]){
            i+=2;
        }else{
            f[i]=1;
            i++;
            ll--;
        }
    }
    
    if(ll%2!=0){
        f[n-1]=1;
        ll--;
    }
    
    printf("%d\n",(n-ll));
    for(int i=0;i<n;i++){
        if(f[i]==0){
            cout<<a[i];
        }
    }
    return 0;
}
​

D

# include <bits/stdc++.h>
using namespace std;
​
typedef long long LL;
LL gcd(LL a,LL b)
{
    return b==0?a:gcd(b,a%b);
}
LL lcm(LL a,LL b)
{
    return a/gcd(a,b)*b;
}
const LL MAXN=1e6+10;
//LL f[MAXN];
int main()
{
    int t;
    scanf("%d",&t);
    
    while(t--){
        LL n;
        LL a[330];
        LL ans=1;
        LL minn=1e6;
        map<LL,bool> b;
        //memset(f,0,sizeof(f));
        scanf("%lld",&n);
        for(int i=0;i<n;i++){
            scanf("%lld",&a[i]);
            ans=lcm(ans,a[i]);
            if(a[i]<minn) minn=a[i];
            b[a[i]]=true;
        }
        if(b[ans]){
            ans=ans*minn;
        }
        printf("%lld\n",ans);
    }
    
    return 0;
}
​



这篇关于Codeforces Round #560 (Div. 3)的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!