CF-Edu-163(已更新:A B)
CF-EDU-163
“分就是用来掉的”我真是自己都佩服我自己的心态了已经(╬▔皿▔)╯
虽然明天还有个比赛>﹏<,但是这场一定要补到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
赛时还试过dfs——tle了,还在输入里加过break……
分析
对于当前数字
- 如果是一位数,他对后一个数的贡献就是它本身,
- 如果是二位数,要考虑是否可拆,因为像65这样十位数与个位数成逆序的数,拆开就不合法,对于可拆的数字,其十位数要大于等于上一个数的贡献,同时十位与个位非递减,其对下一个数字的贡献是它的个位数,不可拆的话就是它本身
操作
声明pre为上一个数对当前数的贡献,若遍历时出现pre>x则不可行,判断这个之后再按两种情况更新pre
注意若更新在判断之前,pre在判断时就变成了当前数对下一个数的贡献,所以pre的更新要在判断之后
代码
#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;//注意pre的初值为0
rep(i,1,n){
cin>>x;
if(pre>x){
f=0;
}
if(x>9&&x/10>=pre&&x/10<=x%10) pre=x%10;//可拆
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;
}