QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#695790#5433. Absolute DifferenceDiverbeeWA 1ms4028kbC++142.5kb2024-10-31 20:48:172024-10-31 20:48:17

Judging History

你现在查看的是最新测评结果

  • [2024-10-31 20:48:17]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:4028kb
  • [2024-10-31 20:48:17]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
using ld = long double;
using ll = long long;


ld qi(pair<ld,ld> a,pair<ld,ld> b){
    if(a>b)swap(a,b);

    if(a==b){
        return (a.second-a.first)*1.0/3;
    }
    if(a.first==a.second){
        return (b.first+b.second)*1.0/2 - a.first;
    }
    if(b.first==b.second){
        return b.first - (a.first+a.second)/2;
    }

    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;
    }
}
ll ssm1=0,ssm2 = 0;

ld quan1(pair<int,int> p){
    if(ssm1)return p.second- p.first;
    else return 1;
}

ld quan2(pair<int,int> p){
    if(ssm2)return p.second- p.first;
    else return 1;
}

signed main(){
    int n,m;cin>>n>>m;
    vector<pair<ld,ld> > vc1(n);
    vector<pair<ld,ld> > vc2(m);

    for(auto &it:vc1)cin>>it.first>>it.second,ssm1+=it.second - it.first;
    for(auto &it:vc2)cin>>it.first>>it.second,ssm2+=it.second - it.first;
    sort(vc1.begin(),vc1.end());
    sort(vc2.begin(),vc2.end());

    ld zq1=0,zq2=0;
    for(auto it:vc1)zq1+=quan1(it);
    for(auto it:vc2)zq2+=quan2(it);

    ld ans =0;
    ld sm1=0,sm2=0;
    ld he1 = 0,he2=0;
    for(auto it:vc2)sm2 += quan2(it)*(it.second-it.first)/2,he2+=quan2(it);
    int p = 0,q=0;
    for(auto it:vc1){
        while (p<vc2.size()&&vc2[p].second<=it.first){
            sm1 += quan2(vc2[p])*(vc2[p].second - vc2[p].first)/2;
            he1 += quan2(vc2[p]);
            p++;
        }
        while(q<vc2.size()&&vc2[q].first<=it.second){
            sm2 -= quan2(vc2[q])*(vc2[q].second - vc2[q].first)/2;
            he2 -= quan2(vc2[q]);
            q++;
        }
        ld uu = 0;
        uu = (it.second-it.first)/2*he1 - sm1;
        uu += sm2 - (it.second - it.first)/2*he2;

        for(int i = p;i<q;++i){
            uu += quan2(vc2[p])*qi(it,vc2[i]);
        }
        uu/=zq2;
        ans += uu*quan1(it);
    }

    cout<<fixed<<setprecision(12)<<ans/zq1;

    return 0;

}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3804kb

input:

1 1
0 1
0 1

output:

0.333333333333

result:

ok found '0.333333333', expected '0.333333333', error '0.000000000'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3928kb

input:

1 1
0 1
1 1

output:

0.500000000000

result:

ok found '0.500000000', expected '0.500000000', error '0.000000000'

Test #3:

score: 0
Accepted
time: 1ms
memory: 3972kb

input:

1 1
-1000000000 1000000000
-1000000000 1000000000

output:

666666666.666666666686

result:

ok found '666666666.666666627', expected '666666666.666666627', error '0.000000000'

Test #4:

score: 0
Accepted
time: 0ms
memory: 4028kb

input:

1 1
-1000000000 0
0 1000000000

output:

1000000000.000000000000

result:

ok found '1000000000.000000000', expected '1000000000.000000000', error '0.000000000'

Test #5:

score: 0
Accepted
time: 0ms
memory: 3820kb

input:

1 1
-1000000000 -1000000000
-1000000000 1000000000

output:

1000000000.000000000000

result:

ok found '1000000000.000000000', expected '1000000000.000000000', error '0.000000000'

Test #6:

score: 0
Accepted
time: 0ms
memory: 3904kb

input:

1 1
-999999999 1000000000
-1000000000 -1000000000

output:

999999999.500000000000

result:

ok found '999999999.500000000', expected '1000000000.500000000', error '0.000000001'

Test #7:

score: -100
Wrong Answer
time: 0ms
memory: 4028kb

input:

1 1
-1000000000 1000000000
-999999999 -999999999

output:

-999999999.000000000000

result:

wrong answer 1st numbers differ - expected: '999999999.0000000', found: '-999999999.0000000', error = '2.0000000'