QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#395797#6749. TargetpotremzWA 0ms3812kbC++171013b2024-04-21 19:28:022024-04-21 19:28:03

Judging History

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

  • [2024-04-21 19:28:03]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3812kb
  • [2024-04-21 19:28:02]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const double eps = 1e-4;
double a, b;
map<double, int>cnt;
bool have_answer;
void dfs(double x, string ans) {
	if (have_answer) {
		return;
	}
	if (cnt.count(x)) {
		if (cnt[x] < ans.size()) {
			return;
		} else {
			cnt[x] = ans.size();
		}
	}
	if (ans.size() > 50) {
		return;
	}
	if (fabs(x - b) <= eps) {
		have_answer = 1;
		cout << ans << ' '<< x ;
		return;
	}
	if (x > b) {
		cnt[x / 2] = ans.size() + 1;
		dfs(x / 2, ans + '1');
		if (have_answer) {
			return;
		}
		cnt[(x + 1) / 2] = ans.size() + 1;
		dfs((x + 1) / 2, ans + '2');
		if (have_answer) {
			return;
		}
	} else {
		cnt[(x + 1) / 2] = ans.size() + 1;
		dfs((x + 1) / 2, ans + '2');
		if (have_answer) {
			return;
		}
		cnt[x / 2] = ans.size() + 1;
		dfs(x / 2, ans + '1');
		if (have_answer) {
			return;
		}
	}
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cin >> a >> b;
	string ans = "";
	dfs(a, ans);
	return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3812kb

input:

0.5 0.25

output:

1 0.25

result:

wrong answer wa