QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#173660 | #5433. Absolute Difference | aesthetic | ML | 1ms | 3952kb | C++20 | 1.4kb | 2023-09-10 00:59:16 | 2023-09-10 00:59:16 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
long double f(int l1, int r1, int l2, int r2)
{
if(l1 == l2 && r1 == r2)
{
return (r1 - l1) / 3.0L;
}
if(r1 <= l2 || r2 <= l1)
{
long double E1 = (l1 + r1) / 2.0L;
long double E2 = (l2 + r2) / 2.0L;
return abs(E1 - E2);
}
if(l1 <= l2 && l2 <= r1)
{
long double aux = f(l2, r1, l2, r2) * (r1 - l2) / (r1 - l1);
return aux + f(l1, l2, l2, r2) * (l2 - l1) / (r1 - l1);
}
if(l1 <= r2 && r2 <= r1)
{
long double aux = f(l1, r2, l2, r2) * (r2 - l1) / (r1 - l1);
return aux + f(r2, r1, l2, r2) * (r1 - l2) / (r1 - l1);
}
return f(l2, r2, l1, r1);
}
int main()
{
ios_base::sync_with_stdio(false), cin.tie(NULL);
int n, m;
cin >> n >> m;
vector<pair<int, int>> a(n), b(m);
long double tota = 0, totb = 0;
for(int i = 0; i < n; ++i)
{
cin >> a[i].first >> a[i].second;
tota += (a[i].second - a[i].first);
}
for(int i = 0; i < m; ++i)
{
cin >> b[i].first >> b[i].second;
totb += (b[i].second - b[i].first);
}
long double ans = 0;
for(int i = 0; i < n; ++i)
for(int j = 0; j < m; ++j)
{
auto [l1, r1] = a[i];
auto [l2, r2] = b[j];
long double prob1 = 1.0L / n;
long double prob2 = 1.0L / m;
if(tota)
prob1 = (r1 - l1) / tota;
if(totb)
prob2 = (r2 - l2) / totb;
ans += prob1 * prob2 * f(l1, r1, l2, r2);
}
cout << setprecision(20) << fixed << ans << endl;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3948kb
input:
1 1 0 1 0 1
output:
0.33333333333333333334
result:
ok found '0.333333333', expected '0.333333333', error '0.000000000'
Test #2:
score: 0
Accepted
time: 1ms
memory: 3768kb
input:
1 1 0 1 1 1
output:
0.50000000000000000000
result:
ok found '0.500000000', expected '0.500000000', error '0.000000000'
Test #3:
score: 0
Accepted
time: 1ms
memory: 3884kb
input:
1 1 -1000000000 1000000000 -1000000000 1000000000
output:
666666666.66666666668606922030
result:
ok found '666666666.666666627', expected '666666666.666666627', error '0.000000000'
Test #4:
score: 0
Accepted
time: 1ms
memory: 3920kb
input:
1 1 -1000000000 0 0 1000000000
output:
1000000000.00000000000000000000
result:
ok found '1000000000.000000000', expected '1000000000.000000000', error '0.000000000'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3812kb
input:
1 1 -1000000000 -1000000000 -1000000000 1000000000
output:
1000000000.00000000000000000000
result:
ok found '1000000000.000000000', expected '1000000000.000000000', error '0.000000000'
Test #6:
score: 0
Accepted
time: 0ms
memory: 3816kb
input:
1 1 -999999999 1000000000 -1000000000 -1000000000
output:
1000000000.50000000000000000000
result:
ok found '1000000000.500000000', expected '1000000000.500000000', error '0.000000000'
Test #7:
score: 0
Accepted
time: 1ms
memory: 3952kb
input:
1 1 -1000000000 1000000000 -999999999 -999999999
output:
999999999.00000000052386894822
result:
ok found '999999999.000000000', expected '999999999.000000000', error '0.000000000'
Test #8:
score: 0
Accepted
time: 1ms
memory: 3876kb
input:
1 1 1000000000 1000000000 -1000000000 -1000000000
output:
2000000000.00000000000000000000
result:
ok found '2000000000.000000000', expected '2000000000.000000000', error '0.000000000'
Test #9:
score: -100
Memory Limit Exceeded
input:
1000 1000 -2175 -2174 -1068 -1065 -1721 -1718 777 834 1162 1169 -3529 -3524 3966 3993 1934 1952 -234 -223 -4967 -4947 8500 8510 5272 5276 -6048 -6033 -34 -22 700 705 -7890 -7886 5538 5543 4114 4126 -9201 -9162 -1521 -1519 -5103 -5100 439 441 993 997 -1684 -1680 -8413 -8404 6724 6728 -3242 -3239 2616...