二分 lot - low top lod-lowdown mit-mid top mid-mid down ht-high top hd high down
#include
#include
#include
#include
using namespace std;
void frac_num(int lot, int lod, int mit, int mid, int ht, int hd, int m, int n)
{
if(m * mid == n * mit){
printf("\n");
}
else if(m * mid > n * mit){
putchar('R');
frac_num(mit, mid, mit + ht, mid + hd, ht, hd, m, n);
}
else{
putchar('L');
frac_num(lot, lod, lot + mit, lod+ mid ,mit, mid, m, n);
}
}
void frac_cas(int lot, int lod, int mit, int mid, int ht, int hd, char *s)
{
if(*s == '\0'){
printf("%d %d\n", mit, mid);
}
else if(*s == 'R'){
frac_cas(mit, mid, mit + ht, mid + hd, ht, hd, s + 1);
}
else{
frac_cas(lot, lod, lot + mit, lod+ mid ,mit, mid, s + 1);
}
}
void f()
{
int M, N;
scanf("%d%d", &M, &N);
frac_num(0, 1, 1, 1, 1, 0, M, N);
}
void g()
{
char s[30];
scanf("%s", s);
frac_cas(0, 1, 1, 1, 1, 0, s);
}
int main()
{
int k, cas;
scanf("%d", &cas);
while(cas--){
scanf("%d", &k);
if(k == 1)
f();
else
g();
}
return 0;
}
阅读(1104) | 评论(0) | 转发(0) |