NOTE - Gấp tiền

Tác giả: khuc_tuan

Ngôn ngữ: C++

#include <iostream>
#include <sstream>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <vector>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
using namespace std;

#define Rep(i,n) for(int i=0;i<(n);++i)
#define For(i,a,b) for(int i=(a);i<=(b);++i)
#define Ford(i,a,b) for(int i=(a);i>=(b);--i)
#define Fit(i,v) for(__typeof(v.begin()) i=v.begin();i!=v.end();++i)
#define Fill(a,b) memset((a), (b), sizeof(a))
#define pb push_back
#define MP make_pair

typedef long long LL;

char find( int n, LL p) {
	if(n==1) return 'D';
	if(p==(1LL<<(n-1))) return 'D';
	else if(p<(1LL<<(n-1))) return 'U'+'D' - find(n-1,(1LL<<(n-1))-p);
	else return find(n-1, p-(1LL<<(n-1)));
}

int main() {
	int n;
	LL p;
	while( cin >> n >> p) {
		if(n==0 && p==0) break;
		cout << find( n, p) << endl;
	}
	return 0;
}

Download