QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#253547#6412. Classical Geometry ProblemUrgantTeamCompile Error//C++232.2kb2023-11-17 08:10:172023-11-17 08:10:18

Judging History

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

  • [2023-11-17 08:10:18]
  • 评测
  • [2023-11-17 08:10:17]
  • 提交

answer

#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <vector>
#include <algorithm>
#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

answer.code: In member function ‘double Color::len() const’:
answer.code:33:24: error: ‘sqrt’ was not declared in this scope
   33 |                 return sqrt(sqlen());
      |                        ^~~~
answer.code: In function ‘std::vector<std::pair<Color, double> > find_ans(const Color&)’:
answer.code:54:29: warning: narrowing conversion of ‘(int)((((double)c.Color::r) == (double)(int)L) ? L :  R)’ from ‘int’ to ‘double’ [-Wnarrowing]
   54 |         Color aim{ c.r == L ? L : R, c.g == L ? L : R, c.b == L ? L : R };
      |                    ~~~~~~~~~^~~~~~~
answer.code:54:47: warning: narrowing conversion of ‘(int)((((double)c.Color::g) == (double)(int)L) ? L :  R)’ from ‘int’ to ‘double’ [-Wnarrowing]
   54 |         Color aim{ c.r == L ? L : R, c.g == L ? L : R, c.b == L ? L : R };
      |                                      ~~~~~~~~~^~~~~~~
answer.code:54:65: warning: narrowing conversion of ‘(int)((((double)c.Color::b) == (double)(int)L) ? L :  R)’ from ‘int’ to ‘double’ [-Wnarrowing]
   54 |         Color aim{ c.r == L ? L : R, c.g == L ? L : R, c.b == L ? L : R };
      |                                                        ~~~~~~~~~^~~~~~~