CF-934(已更新:A B)

mono-4 / 2024-03-16 / 原文

CF-934

“分就是用来掉的”

我真是自己都佩服我自己的心态了已经(╬▔皿▔)╯

虽然明天还有个比赛>﹏<,但是这场一定要补到D

A

分析

注意特殊字符是与其相邻的一个字符相等,子串中存在特殊字符的形式的只有"BAAB"(这里的B也可看作字符串的首或尾,A可以有大于2的无数个),它的特殊字符数为2,所以对于任何存在特殊字符的字符串,特殊字符的个数n一定是偶数,所以对于偶数n,我们输出的字符串只要有(n/2)个"BAAB"个子串就行了

操作

结合分析,对于输出存在n个特殊字符的字符串,可以直接输出n/2个"AAB"

代码

#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
#define db(x) cout<<x<<" "<<endl;
#define _db(a,n) for(int i=1;i<=n;i++) cout<<a[i]<<" ";cout<<endl;
#define mem(a) memset(a,0, sizeof(a))
#define rep(i,l,r) for(int i=l;i<=r;i++)
#define per(i,r,l) for(int i=r;i>=l;i--)


void solve(){
	int n;cin>>n;
	if(n&1){
		cout<<"NO"<<endl;
		return;
	}
	cout<<"YES"<<endl;
	rep(i,1,n/2) cout<<"AAB";
	cout<<endl; 
}

signed main()
{
std::ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
	int t;cin>>t;while(t--)
	solve();
	return 0;
}


B

赛时在输入里加break……思路见注释

代码

#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
#define db(x) cout<<x<<" "<<endl;
#define _db(a,n) for(int i=1;i<=n;i++) cout<<a[i]<<" ";cout<<endl;
#define mem(a) memset(a,0, sizeof(a))
#define rep(i,l,r) for(int i=l;i<=r;i++)
#define per(i,r,l) for(int i=r;i>=l;i--)
void solve(){
	int n,x;cin>>n;
	int f=1,pre=0;
	rep(i,1,n){
		cin>>x;
		//对于二位数,十位小于等于个位且十位大于等于上一个数的贡献pre才可以拆 
		if(x>9&&x/10<=x%10&&x/10>=pre){
			pre=x%10; //当前数的贡献是拆开后的个位
		}
		else{
			if(x<pre){//在不可拆的情况下当前数比pre更小,说明不可行 
				f=0;
			}
			else pre=x;// 当前数的贡献就是它本身 
		} 
		
	} 
	if(f) cout<<"YES";
	else cout<<"NO";
	cout<<endl; 
}

signed main()
{
std::ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
	int t;cin>>t;while(t--)
	solve();
	return 0;
}


C