QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#136304#6412. Classical Geometry ProblemetheningWA 1ms3648kbC++172.3kb2023-08-07 20:06:422023-08-07 20:06:45

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-08-07 20:06:45]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3648kb
  • [2023-08-07 20:06:42]
  • 提交

answer

#include "bits/stdc++.h"
#include <iomanip>
using namespace std;

using ll = long long;
using pii = pair<int, int>;

struct color {
	int r, g, b;
};

void solve() {
	color c;
	cin >> c.r >> c.g >> c.b;

	vector<pair<color, double>> ans;

	auto ext = [](int x) {
		return (x == 0 || x == 255);
	};

	auto rnk = [&](color c) {
		int ret = 3;
		if (ext(c.r)) ret--;
		if (ext(c.g)) ret--;
		if (ext(c.b)) ret--;
		return ret;
	};

	auto dist = [&](color c1, color c2) {
		int r = c1.r - c2.r;
		int g = c1.g - c2.g;
		int b = c1.b - c2.b;
		double ans = sqrt(r * r + g * g + b * b);
		return ans;
	};

	auto solve = [&](auto &&solve, color tar) {
		int rk = rnk(tar);
		if (rk == 0) {
			ans.push_back({tar, 3000.0});
			return;
		}
		if (rk == 1) {
			color prev = tar;
			color fac = tar;
			if (!ext(tar.r)) {
				prev.r = 0;
				fac.r = 255;
			}
			else if (!ext(tar.g)) {
				prev.g = 0;
				fac.g = 255;
			}
			else if (!ext(tar.b)) {
				prev.b = 0;
				fac.b = 255;
			}
			double tme = dist(prev, tar);
			ans.push_back({fac, tme});
			solve(solve, prev);
			return;
		}
		if (rk == 2) {
			color prev = tar;
			color fac = tar;
			if (ext(tar.r)) {
				fac.g = fac.b = 0;
				int mn = min(255 - tar.g, 255 - tar.b);
				prev.g += mn;
				prev.b += mn;
			}
			else if (ext(tar.g)) {
				fac.r = fac.b = 0;
				int mn = min(255 - tar.r, 255 - tar.b);
				prev.r += mn;
				prev.b += mn;
			}
			else if (ext(tar.b)) {
				fac.r = fac.g = 0;
				int mn = min(255 - tar.r, 255 - tar.g);
				prev.r += mn;
				prev.g += mn;
			}
			double tme = dist(prev, tar);
			ans.push_back({fac, tme});
			solve(solve, prev);
			return;
		}
		if (rk == 3) {
			color prev = tar;
			color fac = {0, 0, 0};
			int mn = min({255 - tar.r, 255 - tar.g, 255 - tar.b});
			prev.r += mn;
			prev.g += mn;
			prev.b += mn;
			double tme = dist(prev, tar);
			ans.push_back({fac, tme});
			solve(solve, prev);
			return;
		}
	};

	solve(solve, c);
	reverse(begin(ans), end(ans));

	cout << (int)ans.size() << "\n";
	for (auto [c, d]: ans) {
		cout << c.r << " " << c.g << " " << c.b << " " << d << "\n";
	}

}

int main() {
	cout << setprecision(9);
	cin.tie(0)->sync_with_stdio(0);
	int t;
	cin >> t;
	while (t--) {
		solve();
	}	
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3648kb

input:

3
105 255 175
174 174 174
0 0 0

output:

3
0 255 255 3000
255 255 255 185
0 255 0 113.137085
2
255 255 255 3000
0 0 0 140.296115
1
0 0 0 3000

result:

wrong answer too far from the target: (118.562779, 255.000000, 163.424372) instead of (105, 255, 175) (test case 1)