Skip to content

Instantly share code, notes, and snippets.

@ngobach
Created September 20, 2016 05:32
Show Gist options
  • Save ngobach/7edabb709ea57b6c0e18879243ad34f0 to your computer and use it in GitHub Desktop.
Save ngobach/7edabb709ea57b6c0e18879243ad34f0 to your computer and use it in GitHub Desktop.
#include <bits/stdc++.h>
#define _for(i,a,b) for (int i=(a),_b_=(b),_d_=(a<b?1:-1);i!=_b_;i+=_d_)
#define _it(i,v) for (typeof((v).begin()) i = (v).begin(); i != (v).end(); ++i)
#define _all(v) v.begin(), v.end()
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
template<typename T> vector<T> &operator += (vector<T> &v, T x) {v.push_back(x);return v;}
struct P {
LL t,m;
};
bool operator< (const P &a, const P &b) {
LL t = __gcd(a.m,b.m);
return b.m/t*a.t < a.m/t*b.t;
}
bool operator== (const P &a, const P &b) {
LL t = __gcd(a.m, b.m);
return b.m/t*a.t == a.m/t*b.t;
}
bool operator!= (const P &a, const P &b) {
return !(a==b);
}
P operator+ (const P &a, const P &b) {
P p = {
a.t + b.t,
a.m + b.m
};
LL t = __gcd(p.t, p.m);
p.t /= t; p.m /= t;
return p;
}
void solve() {
P l={0,1},r={1,0},a,b={1,1};
cin >> a.t >> a.m;
while (a!=b) {
if (b<a) {
cout << 'R';
P t = b;
b = b+r;
l = t;
} else {
cout << 'L';
P t = b;
b = b+l;
r = t;
}
}
}
int main(){
#ifdef NGOBACH
freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
#endif
ios_base::sync_with_stdio(0);
cin.tie(0);
solve();
}
@ititorit
Copy link

Cách code của thầy rất hay.. e cảm ơn những bài post của thầy... và mong thầy có thể nói rõ cho e cách làm bài http://vn.spoj.com/problems/TCDFZ/ với ạ? e chân thành cảm ơn...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment