E 字符串
中位数 注意进位i->i-1 += 和 奇数 i->i+1 +=26
#include <bits/stdc++.h>
#define rep(i,a,n) for (int i=a;i<=n;i++)
#define pb push_back
#define IO ios::sync_with_stdio(false)
using namespace std;
const int maxn=2e5+5;
typedef long long ll;
int n;
string s,t;
int a[maxn],ans[maxn];
int main(){
cin>>n;
cin>>s;
cin>>t;
for(int i=n-1;i>=0;i--) //进位
{
a[i]=s[i]-'a'+t[i]-'a';
}
for(int i=n-1;i>=1;i--){
if(a[i]>=26){
a[i-1]+=a[i]/26;
a[i]=a[i]%26;
}
}
for(int i=0;i<n-1;i++){
if(a[i]&1){ //肯定会剩余 1
a[i+1]+=26;
}
}
for(int i=0;i<n;i++){
putchar(a[i]/2+'a');
}
cout<<endl;
return 0;
}
F图论有规律 同奇偶性层不能同时出现
#include <bits/stdc++.h>
#define rep(i,a,n) for (int i=a;i<=n;i++)
#define pb push_back
#define mp make_pair
#define IO ios::sync_with_stdio(false)
#define fi first
#define se second
using namespace std;
const int maxn=2e5+5;
typedef long long ll;
typedef pair<int,int> pii;
int n,m;
string s,t;
int a[maxn],layer[maxn],vis[maxn],color[maxn];
vector<int> g[maxn];
void bfs(){
queue<int> q;
q.push(1); //顶点1压入
layer[1]=1; //1在第一层
while(!q.empty()){
int now=q.front();
q.pop();
if(vis[now])
continue;
vis[now]=1;
for(int i=0;i<g[now].size();i++){
int to=g[now][i];
layer[to]=layer[now]+1;
q.push(to);
}
}
}
int main(){
cin>>n>>m;
int a,b,f=1;
vector<pii> e(m+1);//m条边
rep(i,1,m){
cin>>a>>b;
g[a].pb(b);
g[b].pb(a);
e[i]={a,b};
}
bfs(); //存图怎么走的 有几层
for(int i=1;i<=m;i++){
if(layer[e[i].fi]%2 == layer[e[i].se]%2){
f=0;
break;
}
if(layer[e[i].fi]%2==1 && layer[e[i].se]%2==0)
color[i]=1;
}
if(f){
cout<<"YES"<<endl;
for(int i=1;i<=m;i++)
cout<<color[i];
cout<<endl;
}
else
cout<<"NO"<<endl;
return 0;
}