首页 > 其他分享 >Codeforces Round 913 (Div. 3)

Codeforces Round 913 (Div. 3)

时间:2023-12-07 19:56:14浏览次数:41  
标签:std int s1 Codeforces long -- solve Div 913

Codeforces Round 913 (Div. 3)

比赛链接

ROOK

题目

思路:

我没有下过国际象棋,但这个题跟国际象棋真是没有一点关系,就是一个简单的输出

代码:

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


void solve(){
    // int n;
    string s;
    cin>>s;
    int x;
    char a;

    a=s[0];
    x=s[1]-'0';
    for(int i=1;i<=8;i++){
        if(x!=i){
            cout<<a<<i<<endl;
        }
    }
    char a1='a';

    for(int i=0;i<8;i++){
        if(a1!=a){
            cout<<a1<<x<<endl;
        }
        a1++;

    }
    return ;
    
}

signed main(){
    int t=1;
    cin>>t;
    
    while(t--){
        solve();
    }
    return 0;

}

B. YetnotherrokenKeoard

题目

思路:

这个就是在说给你一个字符串,然后遇到字符B就是把之前他之前出现的最后一个大写字符删除,遇到b就是把他之前出现的最后一个小写字母删除,看到这里我们就可以用栈来实现,因为我们每次操作都是对栈顶元素进行删除,这样省去我们查找的时间,我们可以用下标映射字符,这样最后对两个栈里的元素进行一个排序即可得到最终的结果

代码:

#include<bits/stdc++.h>
using namespace std;
#define int long long
void solve(){
    // string s;
    // cin>>s;
    // string s1="";
    // // cout<<s1<<endl;
    
    // for(int i=0;i<s.size();i++){
    //     if(s[i]!='B'&&s[i]!='b'){
    //         s1+=s[i];
    //         // cout<<s1<<endl;
            
    //     }

    //     else if(s[i]=='B'){
    //         for(int i=s1.size();i>=0;i--){
    //             if(s1[i]>='A'&&s1[i]<='Z'){
    //                 s1.erase(i,1);
    //                 break;

    //             }
    //         }
    //     }
    //     else if(s[i]=='b'){
    //         for(int i=s1.size();i>=0;i--){
    //             if(s1[i]>='a'&&s1[i]<='z'){
    //                 s1.erase(i,1);
    //                 break;
    //             }
    //         }
    //     }
    // }
    // cout<<s1<<endl;
    // return ;
    //考虑下标产生的影响
    string s;
    cin>>s;
    // std::vector<int> v1,v2;
    std::stack<int> s1,s2;//栈
    std::vector<int> v;
    for(int i=0;i<s.size();i++){
        if(s[i]!='B'&&s[i]!='b'){
            if(s[i]>='A'&&s[i]<='Z'){
                s1.push(i);
            }
            else{
                s2.push(i);
            }
        }
        else if(s[i]=='B'){
            if(s1.size()){
                s1.pop();
            }
        }
        else if(s[i]=='b'){
            if(s2.size()){
                s2.pop();  
            }
        }
    }
    while(s1.size()){
        v.push_back(s1.top());
        s1.pop();

    }
    while(s2.size()){
        v.push_back(s2.top());
        s2.pop();
    }
    sort(v.begin(),v.end());
    for(auto x:v){
        cout<<s[x];

    }
    cout<<endl;
    return ;
    
}
signed main(){
    int t=1;
    cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

C. Removal of Unattractive Pairs

题目

思路:

C题一开始我都思路是正确的,可惜了没有坚持下去,反而浪费了很多时间,下次应该有思路就应该把思路整理完不然很容易错过正确思路
这个题我们只需要判断最多的那个字符就可以了,如果最多的那个字符都能有一个一个与之匹配,那就看省下的字符是是奇数还是偶数,如果不能匹配,那就输出差几个匹配位置就可以了

代码:

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

//突然想到了这应该是一个贪心问题
void solve(){
    int n;
    cin>>n;

    string s;
    cin>>s;
    // // memset(a,0,sizeof a);
    map<char,int> mp;

    int maxn=0;
    char x;

    for(int i=0;i<s.size();i++){
        mp[s[i]]++;
        if(maxn<mp[s[i]]){
            maxn=mp[s[i]];
            x=s[i];

        }
    }
    // cout<<maxn<<endl;
    // return ;
    // for(int i=0;i<n;i++){
    //     if(s[i]!=x){
    //         maxn--;
    //     }
    // }
    // if(maxn<=0){
    //     cout<<0<<endl;
    //     return ;

    // }
    // else{
    //     cout<<maxn<<endl;
    //     return ;
        
    // }
    int ans=n-maxn;
    if(ans==maxn){
        cout<<0<<endl;
        return ;
    }
    else if(ans>maxn){
        ans-=maxn;
        if(ans%2){
            cout<<1<<endl;
            return ;
        }
        else{
            cout<<0<<endl;
            return ;

        }
    }
    else{
        cout<<maxn-ans<<endl;
        return ;
        
    }
    
    return ;
    
}
signed main(){
    int t=1;
    cin>>t;
    while(t--){
        solve();
    }
    return 0;

}

E. Good Triples

题目

思路:

感觉是最简单的一道题

代码:

#include<bits/stdc++.h>
using namespace std;
#define int long long 
void solve(){
	int n;
	cin>>n;
	int ans=1;
	while(n>0){
		int x=n%10;
		ans*=(x+1)*(x+2)/2;
		n/=10;

	}
	cout<<ans<<endl;
	return ;
	

}
signed main(){
	int t=1;
	cin>>t;
	while(t--){
		solve();
	}
	return 0;

}

标签:std,int,s1,Codeforces,long,--,solve,Div,913
From: https://www.cnblogs.com/du463/p/17883813.html

相关文章

  • CodeForces 1901F Landscaping
    洛谷传送门CF传送门还是很有趣的一道题。场上直接暴拆式子,要维护动态凸包,本来以为是\(\log^2\)的,写着写着发现是\(\log^3\),遂弃。显然梯形面积最小等价于\(y_0+y_1\)最小,而\(y_0+y_1\)最小等价于梯形在\(m=\frac{n}{2}\)处最小。把上凸包建出来,发现过\(x=m......
  • Codeforces Round 913 (Div. 3)
    CodeforcesRound913(Div.3)div3两题新纪录..我再也不喝完酒打cf了A.Rook#include<bits/stdc++.h>//#defineintlonglong#defineendl'\n'usingnamespacestd;intboard[10][10];voidsolve(){strings;cin>>s;intx=s[0]-&#......
  • 【题解】CodeForces 1902F Trees and XOR Queries Again
    传送门:https://codeforces.com/contest/1902/problem/F数据结构题,这里讲两种思路。$ST$表思路:判定“从若干个数中能否取出其中一些,使得异或和为$x$”的问题,第一时间想到线性基,本题要做的显然就是快速求出询问路径上所有数的线性基。两组数的线性基可以合并,方法为“暴力将......
  • Educational Codeforces Round 158 (Rated for Div. 2)
    Preface补题,妈的现在EduE都做不来这搞毛啊A.LineTrip签到#include<cstdio>#include<iostream>#include<utility>#include<vector>#include<cstring>#include<cmath>#include<cstdlib>#include<algorithm>#include<queue&......
  • Codeforces Round 913 (Div. 3)(A~F)
    A.Rook题意:在一个国际象棋棋盘中,横坐标为a-h,纵坐标为1-8,字母在前,数字在后,输入一个棋子的位置,输出该棋子所在的行与列中非棋子本身位置的所有位置。分析:模拟。代码:#include<iostream>#include<algorithm>usingnamespacestd;typedeflonglongll;constintN=2e5......
  • 【题解】CodeForces 686E Optimal Point
    传送门:https://codeforces.com/contest/686/problem/E前言:本题解来源于作者某天晚上和一位朋友的发电内容(没错,这个作者直接把自己和朋友发电时发的话用markdown排了一下,传上来了),当时本来就比较口语化,加上作者的做法又实在太过离谱,因此可能语言表述不够清晰,对此深感抱歉qwq;离......
  • Codeforces Round 912 (Div. 2)
    Preface这场题莫名很对我胃口,因为F是个究极套路题,还是我最拿手的2-SAT,想+写不到半小时就搞定了然后E的核心思想和上周末VP的一场省赛的题一样,因此看一眼就会了唯一抽象的是D2要用对超集的sosdp,由于之前没写过就不知道还能这么搞A.HalloumiBoxes当\(k\ge2\)时,我们总可以通......
  • CodeTON Round 7 (Div. 1 + Div. 2, Rated, Prizes!)
    Preface补题,经典不会F,看了会题解发现看不懂,索性直接开摆A.JaggedSwaps判断\(a_1\)是否为\(1\)即可#include<cstdio>#include<iostream>#include<utility>#include<vector>#include<cstring>#include<cmath>#include<cstdlib>#include<al......
  • CodeForces 1497E2 Square-free division (hard version)
    洛谷传送门CF传送门感觉和CF1889C2Doremy'sDryingPlan(HardVersion)有异曲同工之妙。显然去除每个数的平方因子后,两个数相乘为完全平方数当且仅当它们相等。考虑若确定了分段方案,那么修改次数就是,每一段重复出现的数的个数。那么我们设\(f_{i,j}\)为\([1,i]\)......
  • Codeforces Round 805 (Div. 3)
    CodeforcesRound805(Div.3)基本情况A、B、C题秒了。D题一开始读错题了,以为是DP,后面发现是简单贪心,拖了点时间才AC。不过无所谓,因为E题没思路了。但是总感觉C做的太不优雅。C.TrainandQueries我的做法就纯用STL无脑模拟。跑了\(701ms\)#include<iostream>#inclu......