3.27
1.
1 #include<bits/stdc++.h> 2 3 #define int long long 4 using namespace std; 5 string a,b; 6 //计算状态 7 int cal(char x,char y) 8 { 9 if(x=='#'&&y=='.') return 1; 10 else if(x=='.'&&y=='#') return 2; 11 else return 3; 12 } 13 signed main() 14 { 15 cin>>a>>b; 16 int n=a.size(); 17 /* 18 状态 1 state 1 * 19 . 20 状态 2 state 2 . 21 * 22 状态 3 state 3 * 23 * 24 */ 25 int ans=0; 26 int lst=-1,state=-1; 27 for(int i=0;i<n;i++) 28 { 29 if(a[i]=='.'&&b[i]=='.') continue; 30 int cur=cal(a[i],b[i]);//当前状态 31 if(lst==-1) 32 { 33 lst=i; 34 state=cur; 35 continue; !!!!!!!!!!!!!!!!!!这里很巧妙!!!!!!!!!!!! 36 } 37 if(cur==1&&state==2||(cur==2&&state==1)) 38 { 39 ans+=i-lst; 40 cur=3; 41 } 42 else ans+=i-lst-1; 43 lst=i;//更新状态 44 state=cur; 45 } 46 cout<<ans<<endl; 47 return 0; 48 }
2.
向上取整:

为什么我在好多别人写的竞赛题里,看到好多一上来就定义一个很大的const 1e多少多少,




◮:
◮:
浙公网安备 33010602011771号