Codeforces Round 910 (Div. 2)

Codeforces Round 910 (Div. 2)

A

模拟

#include <bits/stdc++.h>

using namespace std;
const int N=1e5+10;
char s[N];

void solve(){
    int n , k , cb = 0 , ans = 0;
    cin >> n >> k;
    for(int i = 1 ; i <= n ; i ++){
        cin >> s[i];
        if(s[i] == 'B')cb ++;
    }
    if(cb == k){
        cout << "0\n";
        return ;
    }else{
        cout << "1\n";    
    }
    while(cb < k){
        for(int i = 1 ; i <= n ; i ++){
            if(s[i] == 'A'){
                cb ++;
                if(cb == k){
                    cout << i << " B" << endl;
                    return ;
                }
            }
        }
    }
    while(cb > k){
           for(int i = 1 ; i <= n ; i ++){
            if(s[i] == 'B'){
                cb --;
                if(cb == k){
                    cout << i << " A" << endl;
                    return ;
                }
            }
        }     
    }
}

int main()
{
    int T;
    cin >> T;
    while(T --){
        solve();
    }
    return 0;
}

B

最后一个不能分解,依次往前计算

#include <bits/stdc++.h>

using namespace std;
const int N = 2e5 + 10;
int a[N];

void solve()
{

    int64_t n, res = 0;
    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    for (int i = n - 1; i >= 1; i--)
    {
        if (a[i] > a[i + 1])
        {
            res += ceil(1.0 * a[i] / a[i + 1]) - 1;
            a[i] = a[i] / ceil(1.0 * a[i] / a[i + 1]);
        }
    }
    cout << res << endl;
}

int main()
{
    int T;
    cin >> T;
    while (T--)
    {
        solve();
    }
    return 0;
}

C

一半红一半蓝,当多出奇数时非法

#include <bits/stdc++.h>

using namespace std;
const int N = 2e5 + 10;
int a[N];

void solve()
{
    int n , m , k;
    cin >> n >> m >> k;
    if(n+m-2>k||(k-(n+m-2))%2){
        cout << "No\n";
        return ;
    }
    cout<<"YES"<<endl;
        for(int i=1;i<=n;i++){
            int t=1;
            for(int j=1;j<m;j++){
                if(t){
                    cout<<"R ";
                }else{
                    cout<<"B ";
                }
                t^=1;
            }
            cout<<endl;
        }
        for(int i=1;i<n;i++){
            for(int j=1;j<=m;j++){
                if(j<=2&&i==1){
                    cout<<"B ";
                }else{
                    if((i+j)%2==0){
                        cout<<"R ";
                    }else{
                        cout<<"B ";
                    }
                }
            }
            cout<<endl;
        }
}

int main()
{
    int T;
    cin >> T;
    while (T--)
    {
        solve();
    }
    return 0;
}

D

将每对a,b抽象为线段
相隔时会增加,找相隔最大的

#include <bits/stdc++.h>

using namespace std;
const int N = 2e5 + 10;
int a[N] , b[N];

void solve()
{
    long long ans=0 , n;
    cin>>n;
    for(int i=1;i<=n;i++)cin>>a[i];
    for(int i=1;i<=n;i++)cin>>b[i];
    for(int i=1;i<=n;i++)
    ans+=abs(a[i]-b[i]);
    int maxn=0,minn=1e18;
    //找到最小的右端点和最大的左端点
    for(int i=1;i<=n;i++)
    {
        maxn=max(maxn,min(a[i],b[i]));
        minn=min(minn,max(a[i],b[i]));
    }
    cout<<max(ans,ans+2*(maxn-minn))<<'\n';
}

int main()
{
    int T;
    cin >> T;
    while (T--)
    {
        solve();
    }
    return 0;
}

  • 12
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值