版本比较
UVA11350 Stern-Brocot Tree 题解
正文
增加 6 行删除 6 行
14 行未改动151617181919202122232425262726272829303165 行未改动97989910010110110210310410510610610710810911011011111211311413 行未改动14 行未改动```cpp#include<bits/stdc++.h>#define int long longusing namespace std;struct node {int x,y;}; char s[1010]; int t,x,y; struct node {int x,y;}; char s[1010]; int t,x,y;signed main(){ scanf("%lld",&t); while(t --) { scanf("%s",s+1); node l={0,1},r={1,0},pl={1,1}; for(int i=1;i<=(int)strlen(s+1);i++) if(s[i] == 'L') {r=pl; pl={l.x+pl.x,l.y+pl.y};} for(int i=1;i<=(int)strlen(s+1);i++) if(s[i] == 'L') {r=pl; pl={l.x+pl.x,l.y+pl.y};} else {l=pl; pl={pl.x+r.x,pl.y+r.y};} printf("%lld/%lld\n",pl.x,pl.y); } return 0;65 行未改动}signed main(){ L.a[1][1]=1; L.a[1][2]=1; L.a[2][1]=0; L.a[2][2]=1; R.a[1][1]=1; R.a[1][2]=0; R.a[2][1]=1; R.a[2][2]=1; R.a[1][1]=1; R.a[1][2]=0; R.a[2][1]=1; R.a[2][2]=1; int t; scanf("%lld",&t); while(t -- ) { node res; for(int i=1;i<=2;i++) res.a[i][i]=1; scanf("%s",ch+1); scanf("%s",ch+1); for(int i=1,l=1;i<=(int)strlen(ch+1);i++) { if(i == 1) top=ch[1]; else if(top != ch[i] || i == (int)strlen(ch+1)) else if(top != ch[i] || i == (int)strlen(ch+1)) { if(top == 'L') res=(res*ksm(L,i-1-l+1)),top='R',l=i; else if(top == 'R') res=(res*ksm(R,i-1-l+1)),top='L',l=i; }13 行未改动