Thursday, 7 January 2016

UVa 11350 - Stern-Brocot Tree

//\\__ hr1212 __//\\

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef map<int,int> mi;

#define si(a) scanf("%lld",&a)
#define sii(a,b) scanf("%d %d",&a,&b)
#define siii(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define pi(a) printf("%d\n",a)
#define nl printf("\n");
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define f(i,a,b) for(i=a;i<b;i++)
#define rf(i,a,b) for(i=a;i>=b;i--)
#define clr(x,a) memset(x,a,sizeof(x))
#define MAX 100
#define MOD 1000000007

ll n,m,x,y,x1,y11,x2,y2;

void left(){
    x2=x;y2=y;
    x=x1+x2;y=y11+y2;
}
void right(){
    x1=x;y11=y;
    x=x1+x2;y=y11+y2;
}


int main(){
    ll t,i;
    ll ans=0;string p;

    si(t);
    while(t--){
        cin>>p;
        x1=0;y11=1;x=1;y=1;x2=1;y2=0;
        f(i,0,p.length()){
            if(p[i]=='R')
                right();
            else
                left();
        }
        printf("%lld/%lld\n",x,y);
    }

    return 0;
}

No comments:

Post a Comment