QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#780918 | #8676. Three Kinds of Dice | ucup-team5217# | WA | 151ms | 34296kb | C++23 | 3.6kb | 2024-11-25 14:00:47 | 2024-11-25 14:00:47 |
Judging History
answer
#include <bits/stdc++.h>
#define ld long double
using namespace std;
using ll =long long;
const int N = 1e6 + 10;
int n, m;
int a[N], b[N];
int tot;
ll cntx[N],cnty[N];
int lsh[N];
// int x[N], y[N];
struct vec{
ll x,y;
vec(ll a=0,ll b=0){x=a,y=b;}
vec operator+(const vec a)const {
return {x+a.x,y+a.y};
}
vec operator-(const vec a)const {
return {x-a.x,y-a.y};
}
vec operator*(ll a)const {
return {x*a,y*a};
}
ll operator*(const vec a)const {
return x*a.x+y*a.y;
}
ll operator^(const vec a)const {
return x*a.y-y*a.x;
}
ll len(){
return sqrt(x*x+y*y);
}
ll len2(){
return (x*x+y*y);
}
};
vec p[N];
ld ans;
bool cmp(vec a, vec b) {
return a.x < b.x;
}
ld solve1() {
for (int i = 1; i <= tot; ++i) {
p[i].x = cntx[i];
p[i].y = cnty[i];
// cerr << p[i].x << ' ' << p[i].y << ' ' << lsh[i] << '\n';
}
sort(p + 1, p + tot + 1, cmp);
vector<vec> q;
for (int i = 1; i <= tot; ++i) {
while (q.size() >= 2 && (((p[i] - q[q.size() - 2]) ^ (q[q.size() - 1] - q[q.size() - 2])) >= 0)) q.pop_back();
q.push_back(p[i]);
}
// for (int i = 0; i < q.size(); ++i) {
// cerr << q[i].x << ' ' << q[i].y << '\n';
// }
for (int i = 0; i + 1 < q.size(); ++i) {
if (q[i].x <= 0 && q[i + 1].x >= 0) {
return q[i].y + (ld)(q[i + 1].y - q[i].y) * ((ld)(-q[i].x) / (q[i + 1].x - q[i].x));
}
}
return 0;
}
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i) {
scanf("%d", &a[i]);
}
scanf("%d", &m);
for (int i = 1; i <= m; ++i) {
scanf("%d", &b[i]);
}
sort(a + 1, a + n + 1);
sort(b + 1, b + m + 1);
long long cnt = 0;
for (int i = 1; i <= m; ++i) {
cnt += lower_bound(a + 1, a + n + 1, b[i]) - a - 1;
cnt -= (n - (upper_bound(a + 1, a + n + 1, b[i]) - a) + 1);
}
if (cnt > 0) {
swap(n, m);
swap(a, b);
}
auto ope=[&](){
// cerr << n << ' ' << m << '\n';
tot = 0;
for (int i = 1; i <= n; ++i) {
lsh[++tot] = max(1, a[i] - 1);
lsh[++tot] = a[i];
lsh[++tot] = min(1000000001, a[i] + 1);
}
for (int i = 1; i <= m; ++i) {
lsh[++tot] = max(1, b[i] - 1);
lsh[++tot] = b[i];
lsh[++tot] = min(1000000001, b[i] + 1);
}
sort(lsh + 1, lsh + tot + 1);
tot = unique(lsh + 1, lsh + tot + 1) - lsh - 1;
for (int i = 1; i <= tot; ++i) {
cntx[i] += lower_bound(a + 1, a + n + 1, lsh[i]) - a - 1;
cntx[i] -= (n - (upper_bound(a + 1, a + n + 1, lsh[i]) - a) + 1);
}
for (int i = 1; i <= tot; ++i) {
cnty[i] += 2 * (lower_bound(b + 1, b + m + 1, lsh[i]) - b - 1);
cnty[i] += (upper_bound(b + 1, b + m + 1, lsh[i]) - lower_bound(b + 1, b + m + 1, lsh[i]));
// cnty[i] /= m;
}
ans = solve1();
for (int i = 1; i <= tot; ++i) cntx[i] = cnty[i] = 0;
};
ope();
printf("%.12Lf ", (ld)ans/m/2);
// return 0;
swap(n, m);
swap(a, b);
for (int i = 1; i <= n; ++i) a[i] = 1000000002 - a[i];
for (int i = 1; i <= m; ++i) b[i] = 1000000002 - b[i];
sort(a + 1, a + n + 1);
sort(b + 1, b + m + 1);
// sort()
ope();
printf("%.12Lf\n", 1 - (ld)ans/m/2);
return 0;
}
/*
6 1 1 6 6 8 8
3 2 4 9
*/
/*
*/
/*
4 9 3 7 5
3 4 2 3
*/
/*
3 3 3 3
1 1
*/
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 28372kb
input:
3 2 4 9 3 1 6 8
output:
0.291666666667 0.750000000000
result:
ok 2 numbers
Test #2:
score: 0
Accepted
time: 4ms
memory: 30276kb
input:
3 1 6 8 6 2 2 4 4 9 9
output:
0.291666666667 0.750000000000
result:
ok 2 numbers
Test #3:
score: 0
Accepted
time: 0ms
memory: 28348kb
input:
1 1 1 2
output:
0.750000000000 0.000000000000
result:
ok 2 numbers
Test #4:
score: 0
Accepted
time: 0ms
memory: 28400kb
input:
5 2 2 2 3 3 6 5 5 6 6 6 7
output:
0.500000000000 0.500000000000
result:
ok 2 numbers
Test #5:
score: 0
Accepted
time: 8ms
memory: 30392kb
input:
6 2 2 7 7 9 9 6 3 3 5 5 10 10
output:
0.250000000000 0.750000000000
result:
ok 2 numbers
Test #6:
score: 0
Accepted
time: 0ms
memory: 30680kb
input:
11 12 11 15 9 3 8 18 4 17 13 9 11 8 18 5 15 12 5 11 11 11 3 8
output:
0.473684210526 0.525000000000
result:
ok 2 numbers
Test #7:
score: 0
Accepted
time: 0ms
memory: 30684kb
input:
20 17 18 29 37 5 15 5 9 37 34 12 38 26 29 2 40 23 20 4 12 23 22 2 24 33 6 19 15 31 1 18 30 11 40 13 2 19 5 39 37 22 9 31 26
output:
0.440503432494 0.554166666667
result:
ok 2 numbers
Test #8:
score: 0
Accepted
time: 4ms
memory: 30508kb
input:
40 52 22 29 52 44 3 69 45 40 73 66 51 2 21 20 51 49 34 72 64 69 68 56 4 6 39 29 18 43 6 56 15 22 31 25 78 59 58 40 66 46 52 24 40 12 56 7 4 29 12 26 45 39 27 47 55 45 17 74 28 12 75 77 77 73 41 21 20 23 55 13 58 21 43 11 22 2 67 18 49 56 15 26 25 35 20 61
output:
0.433971447112 0.565224358974
result:
ok 2 numbers
Test #9:
score: 0
Accepted
time: 0ms
memory: 30404kb
input:
76 54 80 5 41 10 124 87 45 67 42 118 33 128 118 21 40 41 3 18 69 131 113 121 106 99 72 108 85 101 108 72 27 13 45 133 137 4 62 30 111 71 39 31 120 79 91 30 58 43 6 60 65 83 83 42 83 26 108 20 133 24 8 125 138 100 21 103 81 45 102 76 44 118 109 18 67 81 4 15 26 65 110 48 126 39 128 82 1 43 134 18 69 ...
output:
0.421188630491 0.573711063373
result:
ok 2 numbers
Test #10:
score: 0
Accepted
time: 0ms
memory: 28340kb
input:
96 11 1 23 7 6 41 8 11 40 5 24 32 40 40 24 24 24 23 17 21 27 21 21 42 1 29 15 45 24 44 50 1 34 11 7 1 12 45 15 3 14 9 25 5 5 20 31 1 41 44 7 27 28 11 24 37 50 7 7 48 1 22 4 5 40 32 33 32 18 18 26 49 28 34 42 29 15 18 4 42 12 21 17 10 47 2 44 40 8 15 7 44 25 5 13 19 88 16 30 20 24 2 26 39 28 1 16 10 ...
output:
0.481854838710 0.518595041322
result:
ok 2 numbers
Test #11:
score: 0
Accepted
time: 0ms
memory: 28344kb
input:
208 31 110 162 24 386 12 262 283 384 392 361 168 58 129 155 45 36 70 2 127 296 380 188 125 148 77 117 272 219 38 79 322 70 91 115 273 228 375 398 353 277 307 258 60 42 60 298 109 60 158 192 159 29 165 103 51 304 313 392 113 62 149 203 152 3 373 206 144 136 214 151 348 287 181 202 367 67 138 388 93 3...
output:
0.495587799090 0.504427083333
result:
ok 2 numbers
Test #12:
score: 0
Accepted
time: 0ms
memory: 28364kb
input:
1170 1311 1924 962 906 1767 1811 1941 1956 1311 364 371 1825 1155 918 1625 1882 1082 198 889 924 1830 244 589 1639 296 1326 1663 379 1479 1369 729 1698 870 1845 217 888 754 858 966 1887 61 1801 1002 1185 1848 610 1914 1742 409 648 781 445 1217 96 1639 1681 1028 923 123 1234 909 569 747 1182 1538 368...
output:
0.485542699331 0.514105003008
result:
ok 2 numbers
Test #13:
score: 0
Accepted
time: 33ms
memory: 31276kb
input:
22713 21796 19194 13993 27763 16658 14855 3720 21919 4029 27311 21879 4981 25538 24982 5230 7339 4299 26976 30753 39183 38686 25483 3489 12855 28134 34477 25105 39953 31801 23937 31229 26076 32962 33965 6078 33306 15915 21622 3643 29726 2542 27764 4554 17811 17329 10576 26448 24416 30696 3230 3730 1...
output:
0.499529338332 0.500470603064
result:
ok 2 numbers
Test #14:
score: 0
Accepted
time: 11ms
memory: 30676kb
input:
100000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...
output:
0.750000000000 0.000000000000
result:
ok 2 numbers
Test #15:
score: 0
Accepted
time: 15ms
memory: 30388kb
input:
1 1 100000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 100...
output:
0.750000000000 0.000000000000
result:
ok 2 numbers
Test #16:
score: 0
Accepted
time: 38ms
memory: 30672kb
input:
100000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...
output:
0.750000000000 0.000000000000
result:
ok 2 numbers
Test #17:
score: 0
Accepted
time: 26ms
memory: 32448kb
input:
100000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...
output:
0.500004999950 0.499995000000
result:
ok 2 numbers
Test #18:
score: 0
Accepted
time: 33ms
memory: 32528kb
input:
100000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 10000...
output:
0.500000000000 0.500000000000
result:
ok 2 numbers
Test #19:
score: 0
Accepted
time: 151ms
memory: 34136kb
input:
100000 100000 99999 99998 99997 99996 99995 99994 99993 99992 99991 99990 99989 99988 99987 99986 99985 99984 99983 99982 99981 99980 99979 99978 99977 99976 99975 99974 99973 99972 99971 99970 99969 99968 99967 99966 99965 99964 99963 99962 99961 99960 99959 99958 99957 99956 99955 99954 99953 9995...
output:
0.500000000025 0.499999999975
result:
ok 2 numbers
Test #20:
score: 0
Accepted
time: 149ms
memory: 34296kb
input:
100000 100000 99999 99998 99997 99996 99995 99994 99993 99992 99991 99990 99989 99988 99987 99986 99985 99984 99983 99982 99981 99980 99979 99978 99977 99976 99975 99974 99973 99972 99971 99970 99969 99968 99967 99966 99965 99964 99963 99962 99961 99960 99959 99958 99957 99956 99955 99954 99953 9995...
output:
0.500000000000 0.500000000000
result:
ok 2 numbers
Test #21:
score: 0
Accepted
time: 30ms
memory: 30720kb
input:
99818 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ...
output:
0.212675039006 0.787320894634
result:
ok 2 numbers
Test #22:
score: -100
Wrong Answer
time: 42ms
memory: 32612kb
input:
99536 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ...
output:
0.009384890327 0.746592522470
result:
wrong answer 2nd numbers differ - expected: '0.7476316', found: '0.7465925', error = '0.0010390'