QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#555278 | #4226. Cookie Cutter | Fortitude# | WA | 5217ms | 4128kb | C++23 | 3.1kb | 2024-09-09 21:24:33 | 2024-09-09 21:24:34 |
Judging History
answer
#include <bits/stdc++.h>
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define f first
#define s second
using namespace std;
using ll = long long;
using ld = double;
using pii = pair <int, int>;
template<class T> struct Point{
T x, y;
Point(T x = 0, T y = 0): x(x), y(y) {}
using P = Point;
P operator - (P p) const { return P(x - p.x, y - p.y); }
P operator + (P p) const { return P(x + p.x, y + p.y); }
P operator * (T d) const { return P(x * d, y * d); }
P operator / (T d) const { return P(x / d, y / d); }
T cross(P p) const { return x * p.y - y * p.x; }
T cross(P a, P b) const { return (a - *this).cross(b - *this); }
bool side() const {
if(y == 0) return x < 0;
return y < 0;
}
bool operator < (P p) const{
if(side() == p.side()) return cross(p) > 0;
return p.side();
}
friend ostream& operator << (ostream& os, P p){
return os << '(' << p.x << ", " << p.y << ')';
}
};
template<class P> inline pair<int, P> lineInter(P s1, P e1, P s2, P e2){
auto d = (e1 - s1).cross(e2 - s2);
if(d == 0) return {-(s1.cross(e1, s2) == 0), P{0, 0}};
auto p = s2.cross(e1, e2), q = s2.cross(e2, s1);
return {1, (s1 * p + e1 * q) / d};
}
template<class P> inline vector<P> polygonCut(vector<P> poly, P s, P e){
vector<P> res;
for(int i = 0; i < sz(poly); i++){
P cur = poly[i], prev = i ? poly[i - 1] : poly.back();
bool side = s.cross(e, cur) < 0;
if(side != (s.cross(e, prev) < 0))
res.pb(lineInter(s, e, cur, prev).second);
if(side) res.pb(cur);
}
return res;
}
using P = Point<ll>;
const int N = 3e3;
int n, W;
P a[N];
inline ld get(Point<ld> c, Point<ld> d){
vector<Point<ld>> ch = {
Point<ld>(0, 0),
Point<ld>(W, 0),
Point<ld>(W, W),
Point<ld>(0, W)
};
ch = polygonCut(ch, c, c - d);
ld res = 0;
for(int i = 0; i < sz(ch); i++) res += ch[i].cross(ch[(i + 1) % sz(ch)]);
return res / 2;
}
inline ld calc(int v, P L, P R){
Point<ld> c{a[v].x, a[v].y}, l{L.x, L.y}, r{R.x, R.y};
return min(get(c, l), get(c, r));
return 0;
ld tl = 0, tr = 1;
for(int i = 0; i < 30; i++){
ld m1 = tl + (tr - tl) / 3;
ld m2 = tr - (tr - tl) / 3;
if(get(c, l * m1 + r * (1 - m1)) < get(c, l * m2 + r * (1 - m2))) tr = m2;
else tl = m1;
}
return get(c, l * tl + r * (1 - tl));
}
main() {
ios :: sync_with_stdio(false);
cin.tie(nullptr);
cin >> W >> n;
for(int i = 0; i < n; i++) cin >> a[i].x >> a[i].y;
ld ans = 0;
for(int i = 0; i < n; i++){
vector<pair<P, int>> vec = {
{P{0, 1}, 0},
{P{0, -1}, 0},
{P{1, 0}, 0},
{P{-1, 0}, 0}
};
for(int j = 0; j < n; j++){
if(i == j) continue;
vec.pb({a[i] - a[j], -1});
vec.pb({a[j] - a[i], 1});
}
sort(all(vec));
for(int j = 0; j < sz(vec); j++) vec[j].second *= -1;
int cur = 0;
for(int j = 0; j < n; j++) cur += !(a[j] - a[i]).side();
for(int j = 0; j < sz(vec); j++){
cur += vec[j].second;
ans = max(ans, ld(cur) / n - calc(i, vec[j].first, vec[(j + 1) % sz(vec)].first) / W / W);
}
}
cout << fixed << setprecision(9) << ans;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 4032kb
input:
5 8 1 1 1 2 1 3 2 1 3 1 3 4 4 1 4 2
output:
0.375000000
result:
ok found '0.3750000', expected '0.3750000', error '0.0000000'
Test #2:
score: 0
Accepted
time: 4706ms
memory: 3920kb
input:
10000 2916 93 93 93 278 93 463 93 649 93 834 93 1019 93 1204 93 1389 93 1574 93 1760 93 1945 93 2130 93 2315 93 2500 93 2685 93 2871 93 3056 93 3241 93 3426 93 3611 93 3796 93 3982 93 4167 93 4352 93 4537 93 4722 93 4907 93 5093 93 5278 93 5463 93 5648 93 5833 93 6018 93 6204 93 6389 93 6574 93 6759...
output:
0.009344444
result:
ok found '0.0093444', expected '0.0093444', error '0.0000000'
Test #3:
score: 0
Accepted
time: 4665ms
memory: 3936kb
input:
10000 2916 1000 1000 1000 1151 1000 1302 1000 1453 1000 1604 1000 1755 1000 1906 1000 2057 1000 2208 1000 2358 1000 2509 1000 2660 1000 2811 1000 2962 1000 3113 1000 3264 1000 3415 1000 3566 1000 3717 1000 3868 1000 4019 1000 4170 1000 4321 1000 4472 1000 4623 1000 4774 1000 4925 1000 5075 1000 5226...
output:
0.100000000
result:
ok found '0.1000000', expected '0.1000000', error '0.0000000'
Test #4:
score: 0
Accepted
time: 4661ms
memory: 4128kb
input:
10000 2916 50 50 50 237 50 424 50 610 50 797 50 984 50 1171 50 1358 50 1544 50 1731 50 1918 50 2105 50 2292 50 2478 50 2665 50 2852 50 3039 50 3225 50 3412 50 3599 50 3786 50 3973 50 4159 50 4346 50 4533 50 4720 50 4907 50 5093 50 5280 50 5467 50 5654 50 5841 50 6027 50 6214 50 6401 50 6588 50 6775 ...
output:
0.013518519
result:
ok found '0.0135185', expected '0.0135185', error '0.0000000'
Test #5:
score: 0
Accepted
time: 4106ms
memory: 4092kb
input:
3000 2999 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 27 27 28 28 29 29 30 30 31 31 32 32 33 33 34 34 35 35 36 36 37 37 38 38 39 39 40 40 41 41 42 42 43 43 44 44 45 45 46 46 47 47 48 48 49 49 50 50 51 51 52...
output:
0.500000000
result:
ok found '0.5000000', expected '0.5000000', error '0.0000000'
Test #6:
score: 0
Accepted
time: 5217ms
memory: 4016kb
input:
10000 3000 2291 3747 7077 9024 8698 5564 5000 4856 7265 103 6672 3043 1458 8108 17 7872 7084 6565 3127 304 6905 9627 5572 6607 1922 489 2273 7798 2548 7044 3082 4225 4242 2287 6284 2489 4802 3096 6902 8724 49 5126 5275 1878 2269 3237 9323 8048 1174 5680 5992 6262 609 433 6690 2531 9430 5618 5410 210...
output:
0.030199134
result:
ok found '0.0301991', expected '0.0301991', error '0.0000000'
Test #7:
score: 0
Accepted
time: 5149ms
memory: 4036kb
input:
10000 3000 156 1582 2398 3319 7701 5829 4040 1938 7464 4347 111 9210 6412 541 4390 4151 2359 7197 2606 1160 594 722 1473 5727 3781 5857 3468 5814 3980 6917 1106 1389 6968 9552 9538 7438 1704 9872 9004 2595 7285 1722 3217 5133 7389 4704 7724 5553 7584 4281 4362 4220 4361 5456 7241 9044 9942 5132 9582...
output:
0.027504748
result:
ok found '0.0275047', expected '0.0275047', error '0.0000000'
Test #8:
score: -100
Wrong Answer
time: 0ms
memory: 4036kb
input:
5 2 2 3 1 4
output:
0.600000000
result:
wrong answer 1st numbers differ - expected: '0.6800000', found: '0.6000000', error = '0.0800000'