Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <queue>
- #include <cmath>
- #include <iomanip>
- #include <fstream>
- using namespace std;
- struct element
- {
- double X;
- int tip;
- };
- struct tochka
- {
- double X;
- double Y;
- };
- void merge(element* a, int left, int mid, int right)
- {
- int i, it = 0;
- int it_two = 0;
- element result[right - left];
- while (left + it < mid and mid + it_two < right)
- {
- if (a[left + it].X < a[mid + it_two].X)
- {
- result[it + it_two] = a[left + it];
- ++it;
- }
- else
- {
- result[it + it_two] = a[mid + it_two];
- ++it_two;
- }
- }
- while (left + it < mid)
- {
- result[it + it_two] = a[left + it];
- ++it;
- }
- while (mid + it_two < right)
- {
- result[it + it_two] = a[mid + it_two];
- ++it_two;
- }
- for (i = 0; i < it + it_two; ++i)
- a[left + i] = result[i];
- }
- void mergeSort_struct(element* a, int n)
- {
- int i, j;
- for (i = 1; i < n; i *= 2)
- for (j = 0; j < n - i; j += 2 * i)
- merge(a, j, j + i, std::min(j + 2 * i, n));
- }
- int Func(double r, int n, tochka* A)
- {
- element E[2 * n];
- double epsilon = 1e-6;
- int i, deg = 0, len = 0;
- for (i = 0; i < n; ++i)
- {
- if (abs(A[i].Y) < r)
- {
- E[2 * i].X = A[i].X - sqrt(r * r - (A[i].Y) * (A[i].Y)) - epsilon * (i + 1);
- E[2 * i].tip = 1;
- E[2 * i + 1].X = A[i].X + sqrt(r * r - (A[i].Y) * (A[i].Y)) + epsilon * (i + 1);
- E[2 * i + 1].tip = 0;
- }
- else
- {
- E[2 * i].X = 0;
- E[2 * i].tip = 2;
- E[2 * i + 1].X = 0;
- E[2 * i + 1].tip = 2;
- }
- }
- mergeSort_struct(E, 2 * n);
- for (i = 0; i < 2 * n; ++i)
- {
- if (deg < 0)
- deg = 0;
- if (E[i].tip == 1)
- {
- deg++;
- if (deg > len)
- len = deg;
- }
- if (E[i].tip == 0)
- deg--;
- }
- return len;
- }
- double binary_search (tochka* A, int n, int k) {
- double L = 0,M;
- double eps = 1e-4;
- double max_y = 0.0;
- for (int i = 0; i < n; ++i)
- {
- if (abs(A[i].Y) > max_y)
- max_y = abs(A[i].Y);
- }
- double R = max_y + 1.0;
- while (R - L > eps)
- {
- M = (R + L) / 2;
- if (Func(M, n, A) < k)
- L = M;
- else
- R = M;
- }
- return R;
- }
- int main()
- {
- int n, k;
- tochka A[n];
- double res;
- int count_tests;
- ifstream ifs("123.txt");
- ifs >> count_tests;
- ofstream out("results.txt");
- for (int i = 0; i < count_tests; ++i)
- {
- ifs >> n;
- ifs >> k;
- tochka A[n] = {};
- for (int i = 0; i < n; ++i)
- {
- ifs >> A[i].X;
- ifs >> A[i].Y;
- cout << A[i].X << " " << A[i].Y << " \n";
- }
- res = binary_search(A, n, k);
- std::cout << std::setprecision(7) << res;
- out << std::setprecision(7) << res;
- out << '\n';
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment