QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#346518 | #4771. Bird tree | PetroTarnavskyi# | AC ✓ | 1ms | 3588kb | C++20 | 1.1kb | 2024-03-08 17:04:50 | 2024-03-08 17:04:51 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (a) - 1; i >= (b); i--)
#define SZ(a) int(a.size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second
typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef double db;
void solve()
{
int a, b;
char c;
cin >> a >> c >> b;
assert(c == '/');
int leNum = 0, leDen = 1, curNum = 1, curDen = 1, riNum = 1, riDen = 0;
string ans;
while ((LL)b * curNum != (LL)a * curDen)
{
if ((LL)b * curNum > (LL)a * curDen)
{
riNum = curNum;
riDen = curDen;
curNum += leNum;
curDen += leDen;
ans += 'L';
}
else
{
leNum = curNum;
leDen = curDen;
curNum += riNum;
curDen += riDen;
ans += 'R';
}
}
for (int i = 1; i < SZ(ans); i += 2)
ans[i] = 'L' + 'R' - ans[i];
cout << ans << "\n";
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
while (t--)
solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3568kb
input:
3 1/2 2/5 7/3
output:
L LRR RLLR
result:
ok 3 lines
Test #2:
score: 0
Accepted
time: 1ms
memory: 3588kb
input:
96 1/2 1/3 1/4 1/5 1/6 1/7 1/8 2/1 2/3 2/5 2/7 3/1 3/2 3/4 3/5 3/7 3/8 4/1 4/3 4/5 4/7 5/1 5/2 5/3 5/4 5/6 5/7 5/8 6/1 6/5 6/7 7/1 7/2 7/3 7/4 7/5 7/6 7/8 8/1 8/3 8/5 8/7 10000/9999 9999/10000 1/10000 10000/1 1000000000/300001 300001/1000000000 701408733/433494437 433494437/701408733 380211999/53852...
output:
L LR LRL LRLR LRLRL LRLRLR LRLRLRL R LL LRR LRLL RL RR LLR LLL LRRL LRRR RLR RRL LLRL LLLR RLRL RLL RRR RRLR LLRLR LLRR LLLL RLRLR RRLRL LLRLRL RLRLRL RLRR RLLR RRRL RRLL RRLRLR LLRLRLR RLRLRLR RLLL RRRR RRLRLRL RRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLR...
result:
ok 96 lines