QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#85693#5667. Meeting PlacesSvyatWA 3ms3772kbC++174.3kb2023-03-08 05:44:152023-03-08 05:44:16

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-08 05:44:16]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:3772kb
  • [2023-03-08 05:44:15]
  • 提交

answer

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

int f(int x) {
	return (x * 233811181LL + 1) % ((1LL << 31) - 1);
}

using dbl = double;

const dbl INF = 1e30;
const dbl EPS = 1e-8;

class MinimumEnclosingCircle {

	class Circle {
	public:
		dbl x, y, r;
		Circle(dbl x, dbl y, dbl r) : x(x), y(y), r(r) {}
	};

	vector<pair<dbl, dbl>> pt;
	
	inline dbl sqr(dbl x) {
		return x * x;
	}

	dbl sqrDist(dbl x, dbl y) {
		return sqr(x) + sqr(y);
	}

	pair<dbl, dbl> getCenter(dbl ax, dbl ay, dbl bx, dbl by, dbl cx, dbl cy) {
		vector<dbl> x = {ax, bx, cx};
		vector<dbl> y = {ax, bx, cx};
		dbl d = 2 * (ax * (by - cy) + bx * (cy - ay) + cx * (ay - by));
		dbl xx = ((sqr(ax) + sqr(ay)) * (by - cy) + (sqr(bx) + sqr(by)) * (cy - ay) + (sqr(cx) + sqr(cy)) * (ay - by)) / d;
		dbl yy = ((sqr(ax) + sqr(ay)) * (cx - bx) + (sqr(bx) + sqr(by)) * (ax - cx) + (sqr(cx) + sqr(cy)) * (bx - ax)) / d;
		return {xx, yy};
	}

	Circle constructCircle(vector<int> &onBoundary) {
		if (onBoundary.empty()) {
			return Circle(0, 0, 0);
		}
		if (onBoundary.size() == 1) {
			return Circle(pt[onBoundary[0]].first, pt[onBoundary[0]].second, 0);
		}
		if (onBoundary.size() == 2) {
			dbl x = (pt[onBoundary[0]].first + pt[onBoundary[1]].first) * 0.5;
			dbl y = (pt[onBoundary[0]].second + pt[onBoundary[1]].second) * 0.5;
			return Circle(x, y, sqr(x - pt[onBoundary[0]].first) + sqr(y - pt[onBoundary[0]].second));
		}
		auto center = getCenter(pt[onBoundary[0]].first, pt[onBoundary[0]].second, pt[onBoundary[1]].first, pt[onBoundary[1]].second, pt[onBoundary[2]].first, pt[onBoundary[2]].second);
		return Circle(center.first, center.second, sqr(center.first - pt[onBoundary[0]].first) + sqr(center.second - pt[onBoundary[0]].second));
	}

	Circle welzl(vector<int> &forbidden, vector<int> &onBoundary) {
		if (pt.size() == forbidden.size() || onBoundary.size() == 3) {
			return constructCircle(onBoundary);
		}
		int nextForbidden = forbidden.empty() ? 0 : forbidden.back() + 1;
		forbidden.push_back(nextForbidden);
		Circle circle = welzl(forbidden, onBoundary);
		if ((sqr(circle.x - pt[nextForbidden].first) + sqr(circle.y - pt[nextForbidden].second)) <= circle.r) {
			forbidden.pop_back();
			return circle;
		}
		onBoundary.push_back(nextForbidden);
		circle = welzl(forbidden, onBoundary);
		forbidden.pop_back();
		onBoundary.pop_back();
		return circle;
	}

public:
	dbl xc;
	dbl yc;
	dbl rSquared;

	void addPoint(dbl x, dbl y) {
		pt.push_back(make_pair(x, y));
		if (pt.size() == 1) {
			xc = x;
			yc = y;
			rSquared = 0;
			return;
		}
		if (sqrDist(x - xc, y - yc) <= rSquared) {
			return;
		}
		vector<int> forbidden;
		vector<int> onBoundary;
		Circle circle = welzl(forbidden, onBoundary);
		xc = circle.x;
		yc = circle.y;
		rSquared = circle.r;
	}
};

dbl calcDp(vector<vector<dbl>> &dp, vector<vector<dbl>> &inv, int num, int m, int optl, int optr) {
	int res = -1;
	dp[num][m] = INF;
	for (int i = optr; i >= optl; --i) {
		if (dp[num][m] >= dp[num - 1][i] + inv[i][m]) {
			dp[num][m] = dp[num - 1][i] + inv[i][m];
			res = i;
		}
	}
	return res;
}

void calc(vector<vector<dbl>> &dp, vector<vector<dbl>> &inv, int num, int l, int r, int optl, int optr) {
	if (l > r) return;
	int mid = (l + r) >> 1;
	int optm = calcDp(dp, inv, num, mid, optl, optr);
	calc(dp, inv, num, l, mid - 1, optl, optm);
	calc(dp, inv, num, mid + 1, r, optm, optr);
}


int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n, k, x1;
	cin >> n >> k >> x1;
	vector<int> x(n);
	vector<int> y(n);
	x[0] = x1;
	y[0] = f(x[0]);
	for (int i = 1; i < n; ++i) {
		x[i] = f(y[i - 1]);
		y[i] = f(x[i]);
	}
	vector<vector<dbl>> mec(n + 1, vector<dbl>(n + 1));
	for (int i = 0; i < n; ++i) {
		MinimumEnclosingCircle m;
		m.addPoint(x[i], y[i]);
		mec[i][i + 1] = 0;
		for (int j = i + 1; j < n; ++j) {
			m.addPoint(x[j], y[j]);
			mec[i][j + 1] = m.rSquared;
		}
	}   
	for (int i = 0; i < (int) mec.size(); ++i) {
		for (int j = i + 1; j < (int) mec.size(); ++j) {
			mec[i][j] = sqrt(mec[i][j]);
		}
	}        
	vector<vector<dbl>> dp(k + 1, vector<dbl>(n + 1, INF));
	dp[0][0] = 0;
	for (int i = 1; i <= k; ++i) {
		calc(dp, mec, i, 1, n, 0, n - 1);
	}
	cout.precision(12);
	cout << fixed << showpoint;
	cout << dp[k][n] << '\n';
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 3752kb

input:

100 23 213

output:

1319350480.800732612610

result:

ok found '1319350480.8007326', expected '1319350480.8007326', error '0.0000000'

Test #2:

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

input:

10 1 1060

output:

1042753143.345167636871

result:

ok found '1042753143.3451676', expected '1042753143.3451676', error '0.0000000'

Test #3:

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

input:

10 10 2373

output:

0.000000000000

result:

ok found '0.0000000', expected '0.0000000', error '-0.0000000'

Test #4:

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

input:

10 2 3396

output:

1236610536.946923017502

result:

ok found '1236610536.9469230', expected '1236610536.9469230', error '0.0000000'

Test #5:

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

input:

10 3 1998

output:

973790809.822444200516

result:

ok found '973790809.8224442', expected '973790809.8224442', error '0.0000000'

Test #6:

score: 0
Accepted
time: 2ms
memory: 3628kb

input:

10 4 562

output:

910867389.906932950020

result:

ok found '910867389.9069330', expected '910867389.9069330', error '0.0000000'

Test #7:

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

input:

10 5 6048

output:

818240814.710514903069

result:

ok found '818240814.7105149', expected '818240814.7105150', error '0.0000000'

Test #8:

score: -100
Wrong Answer
time: 2ms
memory: 3620kb

input:

10 6 2524

output:

674787674.312985420227

result:

wrong answer 1st numbers differ - expected: '500106979.3467762', found: '674787674.3129854', error = '0.3492867'