QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#253548#6412. Classical Geometry ProblemUrgantTeamWA 0ms3768kbC++112.2kb2023-11-17 08:10:512023-11-17 08:10:52

Judging History

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

  • [2023-11-17 08:10:52]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3768kb
  • [2023-11-17 08:10:51]
  • 提交

answer

#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>

using namespace std;

const int L = 0, R = 255;

bool trivial(double c) {
	return c <= L || c >= R;
}

double into_segment(double c) {
	if (c - L <= 1e-9)
		return L;
	if (c - R >= -1e-9)
		return R;
	return c;
}

struct Color {
	double r, g, b;
	bool trivial() const {
		return ::trivial(r) && ::trivial(g) && ::trivial(b);
	}
	double sqlen() const {
		return r * r + g * g + b * b;
	}
	double len() const {
		return sqrt(sqlen());
	}
	Color operator*(const double d) const {
		return { r * d, g * d, b * d };
	}
	Color operator+(const Color other) const {
		return { r + other.r, g + other.g, b + other.b };
	}
	Color operator-(const Color other) const {
		return { r - other.r, g - other.g, b - other.b };
	}
	Color into() const {
		return { into_segment(r), into_segment(g), into_segment(b) };
	}
};

vector<pair<Color, double>> find_ans(const Color& c) {
	if (c.sqlen() == 0)
		return {};
	if (c.trivial())
		return { {c, c.len()} };
	Color aim{ c.r == L ? L : R, c.g == L ? L : R, c.b == L ? L : R	};
	double mult = 1e18;
	if (c.r < aim.r)
		mult = min(mult, (R - L) / (aim.r - c.r));
	if (c.g < aim.g)
		mult = min(mult, (R - L) / (aim.g - c.g));
	if (c.b < aim.b)
		mult = min(mult, (R - L) / (aim.b - c.b));
	Color target = (aim + (c - aim) * mult).into();
	vector<pair<Color, double>> ans = find_ans(target);
	ans.emplace_back(aim, (c - target).len());
	return ans;
}

bool solve_test() {
	Color c;
	if (!(cin >> c.r >> c.g >> c.b))
		return false;
	vector<pair<Color, double>> ans = find_ans(c);
	cout << ans.size() << '\n';
	for (const pair<Color, double>& action : ans)
		cout << action.first.r << ' ' << action.first.g << ' ' << action.first.b << ' ' << action.second << '\n';
	return true;
}

void solve_tests() {
	int t;
	cin >> t;
	for (int i = 0; i < t; ++i)
		if (!solve_test())
			break;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout << setprecision(8) << fixed;
#ifdef ONPC
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	solve_tests();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
105 255 175
174 174 174
0 0 0

output:

3
0.00000000 255.00000000 0.00000000 255.00000000
0.00000000 255.00000000 255.00000000 119.00000000
255.00000000 255.00000000 255.00000000 119.00000000
1
255.00000000 255.00000000 255.00000000 301.37684052
0

result:

wrong output format Expected integer, but "0.00000000" found (test case 1)