Codeforces Round 943 (Div. 3)( 5 / 8 )

A - Maximize?

#include<bits/stdc++.h>
using namespace std;
int gcd(int a,int b){
    return b?gcd(b,a%b):a;
}
void solve(){
    int x;
    cin>>x;
    int g=0,sum,mx=0,ans=0;
    for(int y=x-1;y>=1;y--){
        g=gcd(x,y);
        sum=y+g;
        if(sum>mx){
            ans=y;
            mx=sum;
        }
    }
    cout<<ans<<endl;
}
int main(){
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    int t;
    cin>>t;
    //t=1;
    while(t--)solve();
    return 0;
}

B - Prefiquence

#include<bits/stdc++.h>
using namespace std;
void solve(){
    int n,m;
    cin>>n>>m;
    string s1,s2;
    cin>>s1>>s2;
    int i=0,j=0;
    while(i<n){
        if(j==m)break;
        if(s1[i]==s2[j])j++,i++;
        else j++;
    }
    cout<<i<<endl;
}
int main(){
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    int t;
    cin>>t;
    //t=1;
    while(t--)solve();
    return 0;
}

C - Assembly via Remainders

#include<bits/stdc++.h>
#define int long long
using namespace std;
void solve(){
    int n;
    cin>>n;
    vector<int>a(n),b(n+1);
    for(int i=1;i<n;i++)cin>>a[i];

    b[1]=11451419;
    for(int i=2;i<=n;i++){
        b[i]=b[i-1]+a[i-1];
    }
    for(int i=1;i<=n;i++)cout<<b[i]<<' ';
    cout<<endl;
}
signed main(){
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    int t;
    cin>>t;
    //t=1;
    while(t--)solve();
    return 0;
}

D - Permutation Game

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e7+10;
int p[N],w[N],n,k;
int f(int x){
    int pre=0,ans=w[x]*k;
    for(int i=1;i<=min(n,k);i++){
        pre+=w[x];
        x=p[x];
        ans=max(ans,pre+w[x]*(k-i));
    }
    return ans;
}
void solve(){
    int x,y;
    cin>>n>>k>>x>>y;
    for(int i=1;i<=n;i++)cin>>p[i];
    for(int i=1;i<=n;i++)cin>>w[i];
    int a=f(x),b=f(y);
    if(a>b)cout<<"Bodya"<<endl;
    else if(a<b)cout<<"Sasha"<<endl;
    else cout<<"Draw"<<endl;
}
signed main(){
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    int t;
    cin>>t;
    //t=1;
    while(t--)solve();
    return 0;
}

E - Cells Arrangement

#include<bits/stdc++.h>
using namespace std;
void solve(){
    int n;
    cin>>n;
    cout<<1<<' '<<1<<endl;
    cout<<1<<' '<<2<<endl;
    for(int i=3;i<=n;i++)cout<<i<<' '<<i<<endl;
    cout<<endl;
}
int main(){
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    int t;
    cin>>t;
    //t=1;
    while(t--)solve();
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值