Submission #1045674

# Submission time Handle Problem Language Result Execution time Memory
1045674 2024-08-06T06:53:22 Z VectorLi Mobile (BOI12_mobile) C++14
100 / 100
964 ms 27512 KB
#include <bits/stdc++.h>
#define long long long

using namespace std;

const int N = (int) 1E6;

int n, k;
int x[N], y[N];

/*
为什么这么做的对的,考虑排序线段。
我们排序线段的目的就是为了 连的上!
所以如果线段 i 在 j 之后出现
且 l(i) < l(j)
一定有 r(i) > r(j),这就保证了我们不需要使用排序 
*/

bool valid(double a) {
	double t = 0;
	// t 表示已经可以覆盖 [0, t] 了,初始为空区间 
	// 因为输入的点的坐标是有序的,所以如果当前的 r 只能覆盖线段
	// 的中段的话,t 还会保持是 0 
	for (int i = 0; i < n; i++) {
		if (a < y[i]) {
			continue;
		} 
		double l = x[i] - sqrt(1.0 * a * a - 1.0 * y[i] * y[i]);
		// 直接 y[i] * y[i] 可能会爆
		// 同时,由于 r 大于最大的 abs(y[i]),所以不会出现 sqrt 负数的情况 
		double r = x[i] + sqrt(1.0 * a * a - 1.0 * y[i] * y[i]);
		if (l <= t && r >= t) {
			t = r;
		}
	}
	return t >= k;
}

void solve() {
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		cin >> x[i] >> y[i];
	}
	
	double l = 0, r = 2E9;
	for (int i = 0; i < 100; i++) {
		double m = (l + r) / 2;
		if (valid(m)) {
			r = m;
		} else {
			l = m;
		}
	}
	cout << fixed << setprecision(6);
	cout << r << "\n";
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int t;
	t = 1;
	for (int i = 0; i < t; i++) {
		solve();
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2396 KB Output is correct
2 Correct 0 ms 2512 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 2508 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2396 KB Output is correct
2 Correct 2 ms 2528 KB Output is correct
3 Correct 2 ms 2396 KB Output is correct
4 Correct 3 ms 2596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2396 KB Output is correct
2 Correct 2 ms 2392 KB Output is correct
3 Correct 3 ms 2392 KB Output is correct
4 Correct 3 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2392 KB Output is correct
2 Correct 2 ms 2396 KB Output is correct
3 Correct 2 ms 2396 KB Output is correct
4 Correct 4 ms 2396 KB Output is correct
5 Correct 2 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 45 ms 4700 KB Output is correct
2 Correct 27 ms 5724 KB Output is correct
3 Correct 17 ms 5208 KB Output is correct
4 Correct 70 ms 5896 KB Output is correct
5 Correct 33 ms 5068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 4700 KB Output is correct
2 Correct 59 ms 5464 KB Output is correct
3 Correct 89 ms 5720 KB Output is correct
4 Correct 72 ms 5720 KB Output is correct
5 Correct 79 ms 5976 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 4700 KB Output is correct
2 Correct 28 ms 4744 KB Output is correct
3 Correct 24 ms 4752 KB Output is correct
4 Correct 100 ms 8540 KB Output is correct
5 Correct 65 ms 5628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 35 ms 6748 KB Output is correct
2 Correct 37 ms 6748 KB Output is correct
3 Correct 28 ms 6748 KB Output is correct
4 Correct 98 ms 8736 KB Output is correct
5 Correct 87 ms 8036 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 35 ms 6744 KB Output is correct
2 Correct 43 ms 6744 KB Output is correct
3 Correct 41 ms 6748 KB Output is correct
4 Correct 99 ms 8720 KB Output is correct
5 Correct 86 ms 8028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 167 ms 6772 KB Output is correct
2 Correct 179 ms 6780 KB Output is correct
3 Correct 177 ms 6748 KB Output is correct
4 Correct 477 ms 6792 KB Output is correct
5 Correct 469 ms 13396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 182 ms 6744 KB Output is correct
2 Correct 304 ms 6780 KB Output is correct
3 Correct 142 ms 12368 KB Output is correct
4 Correct 477 ms 15956 KB Output is correct
5 Correct 442 ms 14080 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 194 ms 6748 KB Output is correct
2 Correct 208 ms 6784 KB Output is correct
3 Correct 209 ms 6748 KB Output is correct
4 Correct 575 ms 6776 KB Output is correct
5 Correct 521 ms 14680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 212 ms 6776 KB Output is correct
2 Correct 346 ms 6744 KB Output is correct
3 Correct 183 ms 13568 KB Output is correct
4 Correct 573 ms 18612 KB Output is correct
5 Correct 570 ms 15504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 249 ms 7088 KB Output is correct
2 Correct 254 ms 7036 KB Output is correct
3 Correct 266 ms 6996 KB Output is correct
4 Correct 671 ms 6996 KB Output is correct
5 Correct 581 ms 16112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 251 ms 6992 KB Output is correct
2 Correct 370 ms 7028 KB Output is correct
3 Correct 200 ms 15456 KB Output is correct
4 Correct 684 ms 20480 KB Output is correct
5 Correct 625 ms 17240 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 258 ms 7484 KB Output is correct
2 Correct 271 ms 7508 KB Output is correct
3 Correct 270 ms 7252 KB Output is correct
4 Correct 811 ms 7252 KB Output is correct
5 Correct 696 ms 18512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 277 ms 7248 KB Output is correct
2 Correct 409 ms 7508 KB Output is correct
3 Correct 230 ms 16896 KB Output is correct
4 Correct 765 ms 22976 KB Output is correct
5 Correct 721 ms 19280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 321 ms 8252 KB Output is correct
2 Correct 350 ms 8172 KB Output is correct
3 Correct 347 ms 8016 KB Output is correct
4 Correct 952 ms 8260 KB Output is correct
5 Correct 857 ms 21740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 353 ms 8060 KB Output is correct
2 Correct 483 ms 8260 KB Output is correct
3 Correct 294 ms 20308 KB Output is correct
4 Correct 964 ms 27512 KB Output is correct
5 Correct 902 ms 22900 KB Output is correct