QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#577901 | #8946. 一眼丁真 | wsyear | 100 ✓ | 1834ms | 6296kb | C++23 | 3.7kb | 2024-09-20 15:20:37 | 2024-09-20 15:20:37 |
Judging History
answer
#include <bits/stdc++.h>
#define rep(i, j, k) for (int i = (j); i <= (k); ++i)
#define per(i, j, k) for (int i = (j); i >= (k); --i)
#define SZ(v) int((v).size())
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
using ll = long long;
using pii = std::pair<int, int>;
using pll = std::pair<ll, ll>;
template<class T> void chkmn(T &x, T y) { if (y < x) x = y; }
template<class T> void chkmx(T &x, T y) { if (y > x) x = y; }
using namespace std;
#define double long double
const int maxn = 1010;
const double pi = acosl(-1.);
struct Complex {
double a, b; // a + bi
Complex() { }
Complex(double x, double y) { a = x, b = y; }
friend Complex operator+(Complex x, Complex y) { return Complex(x.a + y.a, x.b + y.b); }
friend Complex operator-(Complex x, Complex y) { return Complex(x.a - y.a, x.b - y.b); }
friend Complex operator*(Complex x, Complex y) { return Complex(x.a * y.a - x.b * y.b, x.a * y.b + x.b * y.a); }
} w[maxn][maxn];
double pw(double x) { return x * x; }
struct point {
double x, y;
point() { }
point(double a, double b) { x = a, y = b; }
friend point operator-(point x, point y) { return point(x.x - y.x, x.y - y.y); }
friend double operator*(point x, point y) { return x.x * y.y - x.y * y.x; }
} a[maxn];
point spin(point x, double a) {
return point(x.x * cosl(a) - x.y * sinl(a), x.x * sinl(a) + x.y * cosl(a));
}
int n, k, p[maxn];
double val[maxn], cur[maxn];
point b[maxn], c[maxn];
vector<double> theta;
double getsum(double x, double y) {
double sum = 0;
rep (i, 1, n) cur[i] = pw(1. - sqrtl(pw(x - a[i].x) + pw(y - a[i].y)));
rep (i, 1, n) sum += cur[i];
return sum;
}
const double eps = 1e-6;
point getO() {
double x = 0, y = 0;
for (double d = 1; d >= 1e-5; d *= .5) {
double nx = x, ny = y, cur = getsum(x, y);
rep (o0, -1, 1) rep (o1, -1, 1) {
double tmp = getsum(x + o0 * d, y + o1 * d);
if (tmp < cur) cur = tmp, nx = x + o0 * d, ny = y + o1 * d;
}
x = nx, y = ny;
}
return point(x, y);
}
double calc(point p, point q, point x) {
return pw((p - x) * (q - x)) / (pw(p.x - q.x) + pw(p.y - q.y));
}
void work() {
cin >> n >> k;
rep (i, 1, n) cin >> a[i].x >> a[i].y;
point O = getO();
rep (i, 1, n) a[i].x -= O.x, a[i].y -= O.y;
sort(a + 1, a + n + 1, [&](point x, point y) {
return atan2l(x.y, x.x) < atan2l(y.y, y.x);
});
rep (i, 1, n) p[i] = i;
sort(p + 1, p + n + 1, [&](int x, int y) {
return pw(a[x].x) + pw(a[x].y) > pw(a[y].x) + pw(a[y].y);
});
theta.clear();
rep (i, 1, min(n, 10)) theta.emplace_back(atan2l(a[p[i]].y, a[p[i]].x));
double mn = 1e18;
int ans = 0;
rep (m, max(3, k - 5), k) {
val[m] = 1e18;
for (double the : theta) {
rep (i, 1, m) b[i] = spin(point(w[m][i - 1].a, w[m][i - 1].b), the);
int mnp = 1;
rep (i, 1, m) if (atan2l(b[i].y, b[i].x) < atan2l(b[mnp].y, b[mnp].x)) mnp = i;
rep (i, 1, m) c[i] = b[(mnp + i - 2) % m + 1];
rep (i, 1, m) b[i] = c[i];
double sum = 0;
int pos = 1;
rep (i, 1, n) {
while (pos <= m && atan2l(b[pos].y, b[pos].x) < atan2l(a[i].y, a[i].x)) pos++;
int pre = (pos == 1 ? m : pos - 1);
if (pos > m) pre = m;
sum += calc(b[pos > m ? 1 : pos], b[pre], a[i]);
}
chkmn(val[m], sum);
}
if (val[m] < mn) mn = val[m], ans = m;
}
cout << ans << '\n';
}
int main() {
rep (m, 3, 30) {
w[m][0] = Complex(1, 0);
Complex e = Complex(cosl(2 * pi / m), sinl(2 * pi / m));
rep (i, 1, m - 1) w[m][i] = w[m][i - 1] * e;
}
cin.tie(nullptr) -> ios::sync_with_stdio(false);
int t; cin >> t;
while (t--) work();
}
Details
Tip: Click on the bar to expand more detailed information
Pretests
Final Tests
Test #1:
score: 10
Accepted
time: 855ms
memory: 6248kb
input:
200 1000 4 -1.65882 -0.468078 -0.559879 0.302541 -1.67025 -0.452322 -0.54312 -1.40252 0.116365 -0.958391 -1.57137 -0.386501 -1.20353 -0.13415 0.123479 -0.934878 -0.597084 -1.41011 -1.69629 -0.489381 -0.0114821 -1.03665 -0.546439 -1.39593 -0.573469 -1.41618 -1.06124 -1.4763 -1.52521 -0.371347 -1.4609...
output:
4 4 3 4 4 3 3 4 4 3 4 4 4 3 4 4 3 4 4 4 4 3 4 3 4 3 3 3 4 3 3 3 3 3 3 3 3 3 4 3 3 4 3 4 3 3 3 3 4 3 3 3 3 4 3 4 3 3 4 4 3 4 3 4 3 4 4 3 3 3 4 3 3 3 4 4 3 3 3 3 4 4 3 3 3 4 3 3 3 3 4 3 4 3 3 3 4 3 3 4 3 3 4 3 4 4 3 3 4 4 3 4 3 4 4 4 3 4 3 4 3 3 3 3 4 3 4 3 3 3 3 3 3 3 4 4 4 3 4 4 3 4 4 4 4 3 3 3 3 3 ...
result:
ok #(wrong) = 0, #(correct) = 200
Test #2:
score: 10
Accepted
time: 859ms
memory: 6200kb
input:
200 1000 4 0.22827 0.536959 -0.743134 0.215561 -0.0821736 -0.804273 0.470104 -0.194576 0.819679 0.553173 0.212657 0.515942 -0.379762 -0.349824 0.140334 -0.864474 -0.033494 0.513621 0.673108 0.243877 0.716308 0.318053 -0.108843 -0.719375 0.102132 -0.924612 0.0141018 -0.921927 0.710421 0.53719 -0.4572...
output:
3 4 3 4 3 3 3 3 4 3 4 4 4 4 4 4 4 3 4 4 3 3 3 4 4 4 4 4 3 3 3 4 4 4 4 4 3 3 3 4 4 4 3 3 4 4 3 4 3 4 3 4 3 3 4 4 3 3 3 4 4 3 4 4 4 4 3 3 3 3 3 3 4 4 3 4 4 4 4 4 3 3 3 4 3 4 3 3 3 3 3 3 3 3 4 4 4 4 4 3 3 3 3 4 3 4 4 3 3 3 4 4 3 4 3 3 4 3 4 3 4 3 4 4 3 4 4 4 3 3 3 3 3 4 4 3 4 4 3 4 4 4 4 4 3 4 3 3 4 3 ...
result:
ok #(wrong) = 0, #(correct) = 200
Test #3:
score: 10
Accepted
time: 1714ms
memory: 4312kb
input:
200 1000 10 0.171063 0.768938 0.339764 0.873943 1.15161 0.672578 0.805594 0.765797 1.15695 0.666805 1.26595 -0.695135 1.20927 0.578729 -0.356686 -0.292753 0.940372 -0.919379 -0.269337 -0.62435 -0.0757841 0.550908 1.52432 0.00176461 -0.366525 0.00974288 0.524328 0.851771 1.37215 0.224858 0.655827 -0....
output:
7 10 7 5 6 8 10 6 8 10 9 5 9 6 10 7 7 5 10 6 10 7 7 10 7 8 8 7 7 7 10 8 6 8 5 7 9 7 5 10 10 7 5 8 6 8 10 8 8 5 7 10 5 8 8 7 5 6 8 10 7 7 6 6 10 8 10 8 5 9 6 6 9 10 6 9 6 5 5 9 7 8 8 7 7 5 5 7 7 8 6 8 10 6 6 6 7 7 8 7 8 8 8 8 8 6 6 9 5 6 10 5 5 5 10 10 10 10 6 10 8 6 9 9 9 6 6 7 9 10 8 8 7 7 6 10 10 ...
result:
ok #(wrong) = 0, #(correct) = 200
Test #4:
score: 10
Accepted
time: 1718ms
memory: 4184kb
input:
200 1000 10 -0.83557 -0.43386 -0.900052 0.302486 0.843787 0.446154 -0.0854311 -0.918758 0.501433 0.844022 -0.955344 -0.173521 0.516729 0.8388 -0.917289 0.0698801 -0.925852 0.0681056 -0.848415 0.471305 0.098655 0.922883 0.958545 0.273256 0.67931 0.611085 -0.951816 -0.0694206 -0.245102 0.947475 0.9397...
output:
8 10 10 6 7 9 7 9 10 8 6 5 10 7 9 8 6 10 8 7 8 5 6 8 6 7 5 7 9 6 5 9 7 5 7 5 10 6 6 6 8 8 10 9 8 5 8 6 9 10 7 7 10 9 9 8 9 7 8 5 5 7 6 6 6 8 5 6 9 6 6 8 9 10 5 6 7 8 8 6 10 8 8 10 10 6 10 9 5 7 5 9 6 7 7 6 5 5 10 7 8 9 6 7 5 5 9 8 7 10 6 9 5 9 10 10 6 9 5 9 10 6 8 9 8 10 6 9 5 10 9 8 5 6 7 7 10 9 5 ...
result:
ok #(wrong) = 0, #(correct) = 200
Test #5:
score: 10
Accepted
time: 1794ms
memory: 4352kb
input:
200 1000 20 1.10645 1.72762 0.00828014 0.0575131 -0.300448 0.537454 0.138879 1.67906 0.73884 1.83804 -0.331532 1.01263 1.57294 1.17098 1.61097 0.722726 0.267742 1.7481 0.805786 -0.115483 1.63489 0.918378 0.358705 -0.0984941 -0.303133 1.14962 1.59952 1.0805 -0.22276 1.35792 1.06748 1.74928 1.48122 1....
output:
19 18 20 19 19 16 20 18 16 15 16 18 16 16 19 20 20 16 19 19 15 19 20 18 16 15 16 19 15 17 19 17 20 18 20 16 20 17 17 16 17 20 20 15 18 18 19 15 16 17 17 18 18 20 16 16 17 18 18 17 20 17 16 18 18 20 18 16 16 17 18 16 19 15 19 15 15 16 19 20 17 19 16 16 18 16 15 15 16 15 18 17 17 15 18 17 15 17 20 16 ...
result:
ok #(wrong) = 0, #(correct) = 200
Test #6:
score: 10
Accepted
time: 1794ms
memory: 4296kb
input:
200 1000 20 0.306231 0.947555 -0.470695 -0.867584 0.0798229 -0.979712 0.972425 -0.18076 0.205552 0.977367 0.503871 -0.843521 0.931879 -0.34759 -0.528287 -0.821234 0.384399 0.889843 0.0427201 -0.995252 0.911209 0.407903 -0.925169 0.281163 1.01054 0.00777535 0.829844 0.506267 0.145597 -0.98502 -0.2980...
output:
19 20 18 15 20 16 15 16 19 16 17 20 19 15 20 19 20 20 19 15 20 17 18 16 20 15 17 16 16 17 17 19 18 15 20 20 16 16 20 17 20 16 15 17 19 15 15 19 16 19 16 18 20 19 18 16 19 19 15 18 15 18 17 15 16 19 20 20 16 18 19 20 17 16 15 15 20 18 16 20 19 20 20 19 15 20 16 19 17 17 20 18 19 20 20 20 20 15 20 20 ...
result:
ok #(wrong) = 0, #(correct) = 200
Test #7:
score: 10
Accepted
time: 1815ms
memory: 4268kb
input:
200 1000 25 -0.150207 0.698438 0.0893216 1.09445 1.69859 -0.01418 0.00876932 1.00054 -0.0563829 0.902229 0.736602 1.41841 -0.147213 0.274848 -0.182403 0.345741 1.63542 -0.149404 1.80616 0.580086 1.56376 -0.247799 0.32449 1.26092 0.627195 1.41568 -0.0382449 -0.105866 0.129226 1.13973 0.0847462 -0.261...
output:
23 22 25 25 21 23 20 22 24 20 23 25 21 23 22 24 24 21 25 25 22 20 24 23 23 21 20 21 25 24 22 24 21 23 22 22 21 24 21 21 21 25 25 20 21 21 24 24 24 22 22 22 21 24 22 22 23 25 20 24 25 22 24 25 23 22 24 21 22 23 22 21 25 21 22 21 20 25 25 22 20 20 20 22 23 24 20 23 24 25 24 25 25 21 24 21 25 20 20 24 ...
result:
ok #(wrong) = 0, #(correct) = 200
Test #8:
score: 10
Accepted
time: 1817ms
memory: 6268kb
input:
200 1000 25 0.964683 -0.212993 0.98252 -0.136339 -0.168828 -0.971035 0.865174 -0.484339 0.571258 -0.82591 -0.797776 -0.589278 -0.307998 -0.948622 -0.80831 0.593024 -0.659663 0.745975 0.923635 -0.380449 0.996853 -0.0380425 0.679349 0.732259 -0.0225609 1.00911 0.717309 -0.710159 -0.425272 -0.901905 0....
output:
21 25 25 25 25 24 24 24 22 22 22 25 25 22 20 24 21 24 21 23 22 21 23 22 21 25 23 25 22 23 22 24 21 25 21 22 20 22 20 23 21 22 23 24 24 22 24 21 22 21 23 23 20 24 25 21 24 25 23 22 24 23 21 20 20 24 23 22 20 24 25 20 20 20 24 23 22 23 22 24 23 25 22 23 25 23 25 20 24 24 25 20 21 24 25 24 21 24 25 21 ...
result:
ok #(wrong) = 0, #(correct) = 200
Test #9:
score: 10
Accepted
time: 1834ms
memory: 6296kb
input:
200 1000 30 -0.823086 -1.0434 0.105428 -0.15483 -0.502513 -0.953264 0.0771079 -0.121858 -1.23449 0.876862 -0.0812511 -0.664993 -0.241982 0.678029 -0.622296 0.896641 -1.20049 0.882673 -1.88268 -0.190726 0.0489134 -0.354098 0.0159866 -0.415372 -0.167045 -0.751293 -0.0637444 -0.612609 0.0696068 -0.3288...
output:
29 28 29 26 26 28 27 30 27 26 28 28 29 28 26 29 28 30 26 28 26 28 28 29 28 28 30 27 27 28 29 26 30 30 27 30 28 30 28 27 27 28 30 25 27 27 28 30 25 30 27 26 25 29 27 26 25 30 27 30 29 28 28 27 27 25 25 25 28 29 25 25 28 29 29 27 27 29 27 29 28 30 25 30 25 28 26 29 27 29 28 29 29 25 25 30 30 27 30 29 ...
result:
ok #(wrong) = 0, #(correct) = 200
Test #10:
score: 10
Accepted
time: 1832ms
memory: 4404kb
input:
200 1000 30 -0.922656 0.353773 0.603763 -0.788179 -0.461439 0.857645 -0.991954 -0.0838754 -0.144937 0.982998 0.605566 -0.771346 0.0629471 0.988433 0.995332 -0.0164629 -0.878948 0.473977 -0.852896 0.501311 0.840425 0.516425 0.440577 0.898323 -0.515795 0.861164 0.116181 -1.00427 -0.477573 -0.879226 0....
output:
25 29 28 29 25 25 25 26 29 27 26 27 30 26 27 28 28 27 25 29 28 25 30 28 27 27 28 29 25 28 26 28 26 30 26 30 30 25 30 25 29 30 26 27 30 28 25 28 28 29 25 27 26 28 25 27 29 26 29 30 28 26 26 29 30 25 28 27 29 29 30 28 29 27 29 30 25 25 26 28 26 25 26 30 25 25 26 29 28 25 25 25 30 27 25 29 25 29 30 27 ...
result:
ok #(wrong) = 0, #(correct) = 200