题目连接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=4060ios
题意:c++
给出两个 $0,1$ 字符串 $S,T$,如今你有两次对 $S$ 做区间翻转($0 \rightarrow 1,1 \rightarrow 0$)的操做,spa
用四元组 $(l_1,r_1,l_2,r_2)$ 表示,表明第一次翻转区间 $[l_1,r_1]$,第二次翻转区间 $[l_2,r_2]$。3d
问你有多少个四元组能够使得 $S=T$。code
题解:blog
把 $S$ 尽量少地分割成若干个子串。若某一子串和相应区间的 $T$ 同样,记做 $B$;反之,则记做 $A$。ci
所以若 $A$ 的数量大于两个,就不可能经过区间翻转两次使得 $S=T$,所以 $A$ 最可能是两个。字符串
分类讨论:get
AC代码:string
#include<bits/stdc++.h> using namespace std; int n; string s,t; int main() { ios::sync_with_stdio(0); cin.tie(0); int T; cin>>T; while(T--) { cin>>n>>s>>t; int cnt=0; for(int i=0;i<n;i++) { if((i==0 || s[i-1]==t[i-1]) && s[i]!=t[i]) cnt++; } if(cnt>2) cout<<"0\n"; else if(cnt==2) cout<<"6\n"; else if(cnt==1) cout<<(2*n-2)<<'\n'; else cout<<((long long)n*(n+1)/2)<<'\n'; } }