QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#372463#6749. TargetQian#TL 1ms3888kbC++141.2kb2024-03-31 13:48:112024-03-31 13:48:12

Judging History

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

  • [2024-03-31 13:48:12]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:3888kb
  • [2024-03-31 13:48:11]
  • 提交

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;
	}
	if (b == 1)
	{
		while (fabs(a - b) > 1e-4)
		{
			cout << 2;
			a = (a - 1) / 2 + 1;
		}
		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: 1ms
memory: 3888kb

input:

0.5 0.25

output:

1

result:

ok ok

Test #2:

score: 0
Accepted
time: 1ms
memory: 3696kb

input:

1 0.75

output:

12

result:

ok ok

Test #3:

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

input:

1 0

output:

11111111111111

result:

ok ok

Test #4:

score: -100
Time Limit Exceeded

input:

0.361954 0.578805

output:


result: