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

Codeforces Round 910 (Div. 2)

时间:2023-12-04 19:14:40浏览次数:37  
标签:int Codeforces long a1 -- Div include 910 define

Codeforces Round 910 (Div. 2)

A. Milica and String

wa麻了,,,不知道自己在干什么

#include <bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;

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

signed main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int T=1;
    cin>>T;
    while(T--)solve();
    return 0;
}

B. Milena and Admirer

今天不宜写题

#include <bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;

const int N = 2e5 + 10;
int a[N];
int n;

void solve(){
    cin>>n;
    int ans=0;
    for(int i=1;i<=n;i++) cin>>a[i];
    for(int i=n-1;i>0;i--){
        if(a[i]<=a[i+1]) continue;
        int x=(a[i] + a[i+1] - 1)/a[i+1];
        a[i]/=x;
        ans+=x-1;
    }
    cout<<ans<<endl;
}

signed main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int T=1;
    cin>>T;
    while(T--)solve();
    return 0;
}

C. Colorful Grid

写着有点恶心,,,自己的码太丑了贴个佬的码

只要在起点处加个环,终点加个U型就行了

#include<iostream>
#include<cstring>
#include<vector>
using namespace std;
using LL = long long;

int main(){

    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(0);

    int T;
    cin >> T;
    while(T--){
        int n, m, k;
        cin >> n >> m >> k;
        if (k < n + m - 2){
            cout << "NO" << '\n';
            continue;
        }
        if (k % 2 != (n + m - 2) % 2){
            cout << "NO" << '\n';
            continue;
        }
        vector<vector<int> > a1(n, vector<int>(m - 1)), a2(n - 1, vector<int>(m));
        for(int i = 0; i < n - 1; i++){
            if (i % 2 == 0){
                a2[i][0] = 1;
            }
        }
        for(int i = 0; i < m - 1; i++){
            if ((n + i - 1) % 2 == 0){
                a1[n - 1][i] = 1;
            }
        }
        if (k % 4 != (n + m - 2) % 4){
            a1[0][0] = a1[1][0] = 1;
        }
        a2[n - 2][m - 1] = a1[n - 1][m - 2] ^ 1;
        a1[n - 2][m - 2] = a1[n - 1][m - 2];
        a2[n - 2][m - 2] = a2[n - 2][m - 1];
        cout << "YES" << '\n';
        for(int i = 0; i < a1.size(); i++){
            for(auto x : a1[i]){
                cout << (x ? "R" : "B") << ' ';
            }
            cout << '\n';
        }
        for(int i = 0; i < a2.size(); i++){
            for(auto x : a2[i]){
                cout << (x ? "R" : "B") << ' ';
            }
            cout << '\n';
        }
    }

}

D

将每个集合当作一个线段。如果两个线段相交,对他们进行交换结果不变。如果两个线段不相交,假设[l1,r1],[l2,r2],l1<r1<l2<r2,对他们交换结果增大2*(l2-r1),因为只交换一次,所以我们要找到最大的那个左端点和最小的那个右端点。

#include <bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;

const int N = 2e5 + 10;
int n;
int a[N];
int b[N];

void solve(){
    cin>>n;
    for(int i=1;i<=n;i++) cin>>a[i];
    for(int i=1;i<=n;i++) cin>>b[i];
    int sum=0;
    int maxl=0;
    int minr=1e9;
    for(int i=1;i<=n;i++){
        sum+=abs(a[i]-b[i]);
        maxl=max(maxl,min(a[i],b[i]));
        minr=min(minr,max(a[i],b[i]));
    }
    if(maxl>=minr)sum+=2*(maxl-minr);
    cout<<sum<<endl;
}

signed main(){
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int T=1;
	cin>>T;
	while(T--) solve();
}

标签:int,Codeforces,long,a1,--,Div,include,910,define
From: https://www.cnblogs.com/zfxyyy/p/17875708.html

相关文章

  • Codeforces Round 909 (Div. 3)
    CodeforcesRound909(Div.3)A#include<bits/stdc++.h>#defineintlonglong#defineendl'\n';usingnamespacestd;intn;voidsolve(){cin>>n;for(inti=1;i<=10;i++){if(i&1){if(n%3==0)n++;......
  • Codeforces Round 911 (Div. 2)
    CodeforcesRound911(Div.2)A.CoverinWater,,,mc无限水#include<bits/stdc++.h>#defineintlonglong#defineendl'\n'usingnamespacestd;voidsolve(){intn;strings;cin>>n>>s;s=""+s+......
  • Codeforces Round 912 (Div. 2)
    CodeforcesRound912(Div.2)什么位运算专场A.HalloumiBoxes#include<bits/stdc++.h>#defineintlonglong#defineendl'\n'usingnamespacestd;inta[110];intn,k;voidsolve(){cin>>n>>k;for(inti=0;i<n;i++)cin&......
  • Educational Codeforces Round 158 (Rated for Div. 2)
    EducationalCodeforcesRound158(RatedforDiv.2)AEDU的题总是感觉写起来怪怪的#include<bits/stdc++.h>#defineintlonglong#defineendl'\n'usingnamespacestd;inta[101];voidsolve(){intn,x;cin>>n>>x;intans=0;......
  • Codeforces Round 912 (Div. 2)补题B、C、D1
    CodeforcesRound912(Div.2)B.StORageroom思路\(a_i\)=\(M_i\)\(_1\)&\(M_i\)\(_2\)&\(M_i\)\(_3\)&...&\(M_i\)\(_n\)\((i!=j)\)ac代码#include<bits/stdc++.h>usingnamespacestd;usingi64=longlong......
  • CF1901 C Add, Divide and Floor 题解
    LinkCF1901CAdd,DivideandFloorQuestion给定一个长度为\(n\)的序列,每次操作你需要选择一个整数\(x\),并将所有\(a_i\)替换为\(\lfloor\frac{a_i+x}{2}\rfloor\)。求至少多少次操作后能将所有\(a_i\)变相同若最少次数小于等于\(n\),输出操作次数和每次操作所选......
  • Educational Codeforces Round 159 (Rated for Div. 2)
    EducationalCodeforcesRound159(RatedforDiv.2)基本情况A题秒了。B题想出来贪心思想,也想出来怎么找最优解了,但实现极其复杂繁琐,最后以先超时优化后又错误的结果告终。B.GettingPoints明显越后面开始学收益越高。然后写了个简单粗暴的纯模拟,T了。#include<iostrea......
  • CodeForces 1900F Local Deletions
    洛谷传送门CF传送门操作没有什么性质,唯一一个性质是,操作次数不超过\(\logn\)(每次至多保留一半元素)。于是我们可以直接模拟操作。但是肯定不能直接模拟。考虑先对原序列模拟一次,求出经过\(i\)次操作后保留的位置集合\(S_i\)。那么只保留\([l,r]\)的元素,可能会造成端点......
  • Codeforces Round 911 (Div. 2)
    Preface忙里偷闲补一下之前欠下的一些CF这场前5个题都极其一眼,然而F瞪了好久愣是屁都不会感觉现在水平有有点到瓶颈了,以前是Div2D写完卡现在是Div2E写完卡,但至少还是在进步的A.CoverinWater如果存在某个空地块的长度大于\(2\)则可以用两个块造出无限水,否则答案就是所有空......
  • Codeforces Round 881 (Div. 3)
    CodeforcesRound881(Div.3)A:ABCA.SashaandArrayColoring题意:求最大的着色成本(着色成本是指同一个颜色的最大值-最小值)思路:肯定不能是相同的,直接最大-最小就行#include<bits/stdc++.h>usingnamespacestd;inta[60];voidsolve(){intn;cin>>n;......