QOJ.ac
QOJ
The 2nd Universal Cup Finals is coming! Check out our event page, schedule, and competition rules!
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#408520 | #6749. Target | H_ZzZ# | WA | 1ms | 3716kb | C++20 | 1.7kb | 2024-05-10 16:16:14 | 2024-05-10 16:16:15 |
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) {
cout << ans << 2;
for (int k = j + 2; k <= i; k++) cout << 1;
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: 1ms
memory: 3664kb
input:
0.5 0.25
output:
1
result:
ok ok
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 3716kb
input:
1 0.75
output:
2
result:
wrong answer wa