QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#372459#6749. TargetQian#TL 0ms3816kbC++141.1kb2024-03-31 13:45:512024-03-31 13:45:52

Judging History

你现在查看的是最新测评结果

  • [2024-03-31 13:45:52]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:3816kb
  • [2024-03-31 13:45:51]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define dd double
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define pii pair<int, int>

const int N = 1e6 + 10;
int n, a[N],b[N];
int sum[N];
void solve()
{
	vector<ll> ans;
	dd a, b;
	cin >> a >> b;
	if (b == 0)
	{
		while (fabs(a - b) > 1e-4)
		{
			cout << 1;
			a /= 2;
		}
		return;
	}
	while (fabs(a - b) > 1e-4)
	{
		if (b < 0.5)
		{
			ans.push_back(1);
			b *= 2;
		} else if (b == 0.5)
		{
			// if (fabs(a - 2 * b + 1) < fabs(a - 2 * b))
			// {
			// 	ans.push_back(2);
			// 	b = 2 * b - 1;
			// } else
			// {

			// }
			if (fabs(a) <= 1e-4)
			{
				ans.push_back(2);
				b = 2 * b - 1;
			} else if (fabs(a - 1) <= 1e-4)
			{
				ans.push_back(1);
				b *= 2;
			}
		} else if(b > 0.5)
		{
			ans.push_back(2);
			b = 2 * b - 1;
		}
	}
	reverse(ans.begin(), ans.end());
	for (auto i : ans)
		cout << i;
}

signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	int _ = 1;
	while (_--)
		solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3692kb

input:

0.5 0.25

output:

1

result:

ok ok

Test #2:

score: 0
Accepted
time: 0ms
memory: 3704kb

input:

1 0.75

output:

12

result:

ok ok

Test #3:

score: 0
Accepted
time: 0ms
memory: 3816kb

input:

1 0

output:

11111111111111

result:

ok ok

Test #4:

score: -100
Time Limit Exceeded

input:

0.361954 0.578805

output:


result: