QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#694476 | #5433. Absolute Difference | xzin | WA | 1ms | 4028kb | C++14 | 1.9kb | 2024-10-31 18:01:59 | 2024-10-31 18:02:00 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using ld = long double;
using ll = long long;
using i128 = __int128;
ld qi(pair<ll,ll> a,pair<ll,ll> b){
if(a>b)swap(a,b);
if(a==b){
return (a.second-a.first)*1.0/3;
}
if(b.first>=a.second){
return ((b.second + b.first) - (a.second + a.first))*1.0/2;
}
if(b.second<=a.second){//包含
ld u = b.first - a.first;
ld v = b.second - b.first;
ld w = a.second - b.second;
ld res = 0;
res += (v/2+u/2)*u + v*(v/3) + w*(w/2 + v/2);
res /= (u+v+w);
return res;
}else{//相交
ld u = b.first - a.first;
ld v = a.second - b.first;
ld w = b.second - a.second;
ld res = 0;
res = u*(v+w+u)/2 + v*(v*v/3+w*(w+v)/2)/(v+w);
res /= (u+v);
return res;
}
}
int main(){
int n,m;cin>>n>>m;
vector<pair<int,int> > vc1(n);
vector<pair<int,int> > vc2(m);
for(auto &it:vc1)cin>>it.first>>it.second;
for(auto &it:vc2)cin>>it.first>>it.second;
sort(vc1.begin(),vc1.end());
sort(vc2.begin(),vc2.end());
ld ans = 0;
int p = 0,q = 0;
ld sm1 = 0,sm2 = 0;
for(auto it:vc2)sm2+=(it.second+it.first)*1.0/2;
for(auto it:vc1){
while (p<vc2.size()&&vc2[p].second<=it.first)
{
sm1 += (vc2[p].first+vc2[p].second)*1.0/2;
p++;
}
while(q<vc2.size()&&vc2[q].first<=it.second){
sm2 -= (vc2[q].first+vc2[q].second)*1.0/2;
q++;
}
ld uu = 0;
uu += p*(it.first+it.second)*1.0/2 - sm1;
uu += sm2 - (it.first+it.second)*1.0/2 * (vc2.size()-q);
for(int i = p ; i< q;++i){
uu += qi(it,vc2[i]);
}
ans += uu;
}
cout<<fixed<<setprecision(13)<<ans/vc1.size()/vc2.size();
// system("pause");
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3824kb
input:
1 1 0 1 0 1
output:
0.3333333333333
result:
ok found '0.333333333', expected '0.333333333', error '0.000000000'
Test #2:
score: 0
Accepted
time: 0ms
memory: 4028kb
input:
1 1 0 1 1 1
output:
0.5000000000000
result:
ok found '0.500000000', expected '0.500000000', error '0.000000000'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3796kb
input:
1 1 -1000000000 1000000000 -1000000000 1000000000
output:
666666666.6666666269302
result:
ok found '666666666.666666627', expected '666666666.666666627', error '0.000000000'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3804kb
input:
1 1 -1000000000 0 0 1000000000
output:
1000000000.0000000000000
result:
ok found '1000000000.000000000', expected '1000000000.000000000', error '0.000000000'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3800kb
input:
1 1 -1000000000 -1000000000 -1000000000 1000000000
output:
1000000000.0000000000000
result:
ok found '1000000000.000000000', expected '1000000000.000000000', error '0.000000000'
Test #6:
score: 0
Accepted
time: 0ms
memory: 3796kb
input:
1 1 -999999999 1000000000 -1000000000 -1000000000
output:
1000000000.5000000000000
result:
ok found '1000000000.500000000', expected '1000000000.500000000', error '0.000000000'
Test #7:
score: 0
Accepted
time: 0ms
memory: 3856kb
input:
1 1 -1000000000 1000000000 -999999999 -999999999
output:
999999999.0000000005239
result:
ok found '999999999.000000000', expected '999999999.000000000', error '0.000000000'
Test #8:
score: 0
Accepted
time: 0ms
memory: 3796kb
input:
1 1 1000000000 1000000000 -1000000000 -1000000000
output:
2000000000.0000000000000
result:
ok found '2000000000.000000000', expected '2000000000.000000000', error '0.000000000'
Test #9:
score: -100
Wrong Answer
time: 1ms
memory: 3776kb
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...
output:
6623.7837545116285
result:
wrong answer 1st numbers differ - expected: '6717.1171457', found: '6623.7837545', error = '0.0138949'