AcWing 1995. 关于这一题理解上的坑(我无法理解!!!)
原题链接
简单
作者:
Verse
,
2022-04-26 19:58:32
,
所有人可见
,
阅读 258
在走的时候要头相对才能打招呼 对应于题目的分开后相遇
有一头牛停下时,遇到就能打招呼 当一头牛停下后的相遇一定是分开后的相遇
# include <bits/stdc++.h>
using namespace std;
const int N = 5e4+10;
char e[N],b[N];
int ed[N],bd[N],esi,bsi;
int main(){
cin >> bsi >> esi;
for(int i = 0; i < bsi;++i){
cin >> bd[i] >> b[i];
}
for(int i = 0; i < esi;++i){
cin >> ed[i] >> e[i];
}
int i = 0,j = 0,cb = 0, ce = 0,ans = 0;
while(i < bsi && j < esi){
if(b[i] == 'L') cb--;
else cb++;
bd[i]--;
if(e[j] == 'L')ce--;
else ce++;
ed[j]--;
if(ce == cb && (b[i] =='L' && e[j] == 'R' || b[i] == 'R' && e[j] == 'L')){
ans++;
}
if(bd[i] == 0)i++;
if(ed[j] == 0)j++;
}
while(i < bsi){
if(b[i] == 'L') cb--;
else cb++;
bd[i]--;
if(ce == cb ){
ans++;
}
if(bd[i] == 0)i++;
}
while(j < esi){
if(e[j] == 'L')ce--;
else ce++;
ed[j]--;
if(ce == cb){
ans++;
}
if(ed[j] == 0)j++;
}
cout << ans << endl;
return 0;
}