QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#408523 | #6749. Target | H_ZzZ# | AC ✓ | 1ms | 3912kb | C++20 | 1.7kb | 2024-05-10 16:23:42 | 2024-05-10 16:23:43 |
Judging History
answer
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<numeric>
#include<stack>
#include<string>
#include<vector>
#include<unordered_map>
#include<algorithm>
#include<cmath>
#include<cstring>
#include <bitset>
#include <map>
#include<queue>
#include <set>
#include<unordered_set>
#include<algorithm>
#include <functional>
#include <iomanip>
#include <time.h>
//#define int long long
#define endl '\n'
#define X first
#define V second
#define ce cout << endl;
#define lowbit(x) (x & -x)
using namespace std;
using LL = long long;
using pii = pair<int, int>;
using pdi = pair<double, int>;
using pip = pair<int, pii>;
using tiii = tuple<int, int, int>;
inline void ini();
const int mod = 1e9 + 7;
const int N = 2e5 + 5;
long double pw2[N];
void solve() {
long double a, b;
cin >> a >> b;
if (a == b) {
return;
}
for (int i = 1; i <= 50; i++) {
long double c = b - a * pw2[i];
if (c >= -1e-4 && c <= 1e-4) {
for (int j = 0; j < i; j++) cout << 1;
return;
}
else if (c < -1e-4) continue;
string ans;
for (int j = 1; j <= i; j++) {
if (c-pw2[j] >= -1e-4 && c - pw2[j] <= 1e-4) {
ans += '2';
for (int k = j + 1; k <= i; k++) ans += '1';
reverse(ans.begin(), ans.end());
cout << ans;
return;
}
if (pw2[j] <= c) ans += '2', c -= pw2[j]; else ans += '1';
}
if (c > 1e-4) continue;
reverse(ans.begin(), ans.end());
cout << ans;
return;
}
}
void ini() {
pw2[0] = 1;
for (int i = 1; i <= 50; i++) pw2[i] = pw2[i - 1] * 0.5;
}
signed main() {
// freopen("D:\\debug.txt", "r", stdin);
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
ini();
int T = 1;
while (T--)
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3668kb
input:
0.5 0.25
output:
1
result:
ok ok
Test #2:
score: 0
Accepted
time: 0ms
memory: 3716kb
input:
1 0.75
output:
12
result:
ok ok
Test #3:
score: 0
Accepted
time: 0ms
memory: 3732kb
input:
1 0
output:
11111111111111
result:
ok ok
Test #4:
score: 0
Accepted
time: 1ms
memory: 3672kb
input:
0.361954 0.578805
output:
111212112
result:
ok ok
Test #5:
score: 0
Accepted
time: 0ms
memory: 3672kb
input:
0.144888 0.140086
output:
122222111211
result:
ok ok
Test #6:
score: 0
Accepted
time: 0ms
memory: 3876kb
input:
0.514397 0.969399
output:
21111122222
result:
ok ok
Test #7:
score: 0
Accepted
time: 0ms
memory: 3696kb
input:
0.887873 0.402213
output:
212211221
result:
ok ok
Test #8:
score: 0
Accepted
time: 0ms
memory: 3720kb
input:
0.152004 0.176414
output:
21221211
result:
ok ok
Test #9:
score: 0
Accepted
time: 0ms
memory: 3740kb
input:
0.401831 0.860762
output:
2111222122
result:
ok ok
Test #10:
score: 0
Accepted
time: 0ms
memory: 3876kb
input:
0.580629 0.869474
output:
12222122
result:
ok ok
Test #11:
score: 0
Accepted
time: 0ms
memory: 3700kb
input:
0.138673 0.508844
output:
2111112
result:
ok ok
Test #12:
score: 0
Accepted
time: 0ms
memory: 3724kb
input:
0.027182 0.263243
output:
22122111121
result:
ok ok
Test #13:
score: 0
Accepted
time: 0ms
memory: 3736kb
input:
0.081714 0.212216
output:
212112212211
result:
ok ok
Test #14:
score: 0
Accepted
time: 0ms
memory: 3892kb
input:
0.562775 0.388603
output:
222122111221
result:
ok ok
Test #15:
score: 0
Accepted
time: 1ms
memory: 3696kb
input:
0.112949 0.147503
output:
2221211211
result:
ok ok
Test #16:
score: 0
Accepted
time: 0ms
memory: 3720kb
input:
0.800247 0.150903
output:
211212211211
result:
ok ok
Test #17:
score: 0
Accepted
time: 0ms
memory: 3776kb
input:
0.300103 0.584619
output:
221212112
result:
ok ok
Test #18:
score: 0
Accepted
time: 1ms
memory: 3892kb
input:
0.844720 0.070148
output:
2221112111
result:
ok ok
Test #19:
score: 0
Accepted
time: 0ms
memory: 3748kb
input:
0.573320 0.123035
output:
222122222111
result:
ok ok
Test #20:
score: 0
Accepted
time: 0ms
memory: 3684kb
input:
0.467281 0.231366
output:
122122211
result:
ok ok
Test #21:
score: 0
Accepted
time: 1ms
memory: 3896kb
input:
0.264769 0.373434
output:
211222222121
result:
ok ok
Test #22:
score: 0
Accepted
time: 1ms
memory: 3716kb
input:
0.689729 0.570712
output:
11112112112
result:
ok ok
Test #23:
score: 0
Accepted
time: 0ms
memory: 3896kb
input:
0.747218 0.312573
output:
1111111112121
result:
ok ok
Test #24:
score: 0
Accepted
time: 0ms
memory: 3700kb
input:
0.215052 0.203677
output:
21111212211
result:
ok ok
Test #25:
score: 0
Accepted
time: 0ms
memory: 3744kb
input:
0.607834 0.733102
output:
1222122212
result:
ok ok
Test #26:
score: 0
Accepted
time: 0ms
memory: 3876kb
input:
0.516860 0.252876
output:
211111121
result:
ok ok
Test #27:
score: 0
Accepted
time: 0ms
memory: 3724kb
input:
0.955285 0.457773
output:
121121212221
result:
ok ok
Test #28:
score: 0
Accepted
time: 0ms
memory: 3748kb
input:
0.156178 0.353262
output:
222112122121
result:
ok ok
Test #29:
score: 0
Accepted
time: 0ms
memory: 3776kb
input:
0.398701 0.040258
output:
12112121111
result:
ok ok
Test #30:
score: 0
Accepted
time: 0ms
memory: 3672kb
input:
0.973859 0.000184
output:
111111111111
result:
ok ok
Test #31:
score: 0
Accepted
time: 0ms
memory: 3912kb
input:
0.882213 0.556709
output:
222112221112
result:
ok ok
Test #32:
score: 0
Accepted
time: 0ms
memory: 3724kb
input:
0.263822 0.460984
output:
11112212221
result:
ok ok
Test #33:
score: 0
Accepted
time: 0ms
memory: 3692kb
input:
0.443432 0.034841
output:
22211121111
result:
ok ok