首页 > 其他分享 >CodeTON Round 7 (Div. 1 + Div. 2, Rated, Prizes!)

CodeTON Round 7 (Div. 1 + Div. 2, Rated, Prizes!)

时间:2023-11-28 22:14:36浏览次数:30  
标签:Rated int ed long Prizes Div define

看到B官方题解写了一堆,而如果能注意到一些性质,几行就写完了

题意:给一个A,B构成的字符串,可以将“AB”翻转成"BA",问最多可以进行多少次翻转?
实际上在手动模拟以后发现,由于题目限制了每个位置只能翻转一次,所以情况简单了不少。
只要还没过最后一个B,那么最后一个B之前的所有A就会被反转。真正无效的部分是开头就是B,以及末尾的A,所以我们只需要找到第一个A,最后一个B即可,这两之间的所有位置都会被颠倒

// Problem: B. AB Flipping
// Contest: Codeforces - CodeTON Round 7 (Div. 1 + Div. 2, Rated, Prizes!)
// URL: https://codeforces.com/contest/1896/problem/B
// Memory Limit: 256 MB
// Time Limit: 1000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include <bits/stdc++.h>
using namespace std;
#define ll long long
//# define int long long
#define ull unsigned long long
#define pii pair<int,int>
#define double long double
#define baoliu(x, y) cout << fixed << setprecision(y) << x
#define endl  "\n"

const int N = 2e5 + 10;
const int M = 1e6 + 10;
const int inf = 0x3f3f3f3f;
const int mod = 998244353;
const double eps = 1e-8;
int n, m;
int a[N];

void solve(){
	cin>>n;
	string s;
	cin>>s;
	int st=-1,ed=n;
int len=s.length();
for(int i=0;i<len;i++){
	if(s[i]=='A'){
	st=i;
	break;
	}
}
for(int i=len-1;i>=0;i--){
	if(s[i]=='B'){
	ed=i;
	break;
	}
}
if(st==-1||ed==n||st>ed)cout<<"0"<<endl;
else cout<<ed-st<<endl;
}
int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);

    int t;
   cin>>t;

    while (t--) {
solve();
    }
    return 0;
}

D题是一个很典的题的变形,考虑再开一个专题来说这一类题,放个链接

标签:Rated,int,ed,long,Prizes,Div,define
From: https://www.cnblogs.com/mathiter/p/17863224.html

相关文章

  • Codeforces Round 911 (Div. 2) D
    CodeforcesRound911(Div.2)DD.SmallGCD题意定义\(f(a,b,c)\)为\(a,b,c\)中较小两个数的\(gcd\),给定数组\(a_{1...n}\),求\(\sum\limits_{i=1}^{n}\sum\limits_{j=i+1}^{n}\sum\limits_{k=j+1}^{n}f(a_i,a_j,a_k)\)题解显然可以先排序,不会影响结果,排完序后\(a_k\)就......
  • CodeTON Round 7 (Div. 1 + Div. 2, Rated, Prizes!)
    CodeTONRound7(Div.1+Div.2,Rated,Prizes!)A-JaggedSwaps思路:a2到an的数只要相邻为逆序都可以交换,只需要判断a1是否为1即可#include<bits/stdc++.h>usingnamespacestd;#defineintlonglong//#defineint__int128#definedoublelongdoubletypedefpai......
  • Codeforces Round 903 (Div. 3)
    CodeforcesRound903(Div.3)A.Don'tTrytoCount大概题意给你两个字符串a,b。a串可进行的操作为将整个a串复制到之前的a串后面(直接用a+a即可),然后看操作多少次可以让b串变为a串的子串如果不能就输出-1。#include<iostream>usingnamespacestd;stringa,b;voidsolve()......
  • Codeforces Round 894 (Div. 3)
    CodeforcesRound894(Div.3)A.GiftCarpet题意:判断一列一个字母有没有“vika”思路:挨个枚举每一列#include<bits/stdc++.h>usingnamespacestd;charmp[25][25];charx[]={'v','i','k','a'};voidsolve(){intm,n;cin>>......
  • Codeforces Round 911 (Div. 2) D. Small GCD
    题目链接:https://codeforces.com/contest/1900/problem/D对于已经排序好的数组\(a\),我们需要计算:\[\sum_{i=1}^n\sum_{j=i+1}^ngcd(a_i,a_j)*(n-j)\]由于\(\sum_{d|n}\phi(d)=n\),因此:\[\gcd(a_i,a_j)=\sum_{d|a_i,d|a_j}\psi(d)\]代入可得:\[\sum_{i=1}^n\su......
  • Codeforces Round 911 (Div. 2) D
    D.SmallGCD题意给定数组\(a\),求出数组\(a\)中所有三元组中较小的两个元素的\(gcd\)的和.分析显然数组中元素的顺序不影响统计答案,为了方便先将数组排个序;枚举中间的元素\(a_j\),那么只有它前边的元素能与其产生贡献,它后边的元素个数就是这个贡献的倍数,下面考虑枚......
  • Codeforces Round 911 (Div. 2)
    CodeforcesRound911(Div.2)A-CoverinWater解题思路:如果存在三个以上相邻的格子需要填,那么答案为二,否则有多少空格答案为多少。代码:#include<bits/stdc++.h>usingnamespacestd;usingll=longlong;typedefpair<int,int>pii;#definefifirst#definese......
  • Codeforces Round 911 (Div. 2) A-C
    CodeforcesRound911(Div.2)A.CoverinWater题意:有n个单元格,有的空着有的被堵住,可以做两种操作:给一个空着的单元格放入水;将单元格的水移到另一个单元格。并且,若一个单元格左右两边都有水,它也会自动充满水。所有空着的单元格都要充满水,求最少的放入水的次数思路:若存在三......
  • CodeTON Round 7 (Div. 1 + Div. 2, Rated, Prizes!)
    20231127A.JaggedSwaps题意是:给你一个数组进行无数次的操作问你能不能单调思路:通过观察发现进行操作大的一定会被放在后面,所以一定会单调,但是操作是从2开始的,所以下表1的地方一定要是1usingnamespacestd;inta[20];voidsolve(){intn;cin>>n;for(in......
  • Codeforces Round 911 (Div. 2)
    A-CoverinWater三个连续的.就可以造出无限水,这时直接输出\(2\),否则输出区间长度和。SubmissionB-LauraandOperations每次操作不会改变不需要的两个数的个数的和的奇偶性,而当这个和为偶数的时候,通过若干操作一定可以全部变成另一个。SubmissionC-Anji'sBinary......