QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#768997 | #9348. Driverless Car | 飞带长队 (Xintong Fang, Jun Zheng, Haifeng Liu) | WA | 325ms | 3940kb | C++17 | 5.6kb | 2024-11-21 15:40:15 | 2024-11-21 15:40:16 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#include"debug.h"
#else
#define debug(...) void()
#endif
#define all(x) (x).begin(),(x).end()
template<class T>
auto ary(T *a,int l,int r){
return vector<T>{a+l,a+1+r};
}
using ll=long long;
using ull=unsigned long long;
using ld=long double;
using vec=complex<ld>;
const ld eps=1e-9;
ld dot(const vec &a,const vec &b){
return real(a)*real(b)+imag(a)*imag(b);
}
ld cross(const vec &a,const vec &b){
return dot(a,b*vec(0,-1));
}
ld dis2(const vec &a){
return dot(a,a);
}
int sign(ld x){
return (x>eps?1:(x<-eps?-1:0));
}
int T,xl,xr,yl,yr;
vec a1,a2,b1,b2;
void read(vec &a){
int x,y;
scanf("%d%d",&x,&y);
a=vec(x,y);
}
vector<vec> common(vec a,vec b,vec x,vec y){
ld s=cross(x-a,y-a),t=cross(y-b,x-b);
if(sign(s+t)==0)return {};
return {a*(t/(s+t))+b*(s/(s+t))};
}
vec arg(vec a){
return a/abs(a);
}
pair<vec,vec> midline(vec a,vec b){
return make_pair((a+b)/ld(2),arg(b-a)*vec(0,1));
}
bool chkin(vec x){
return
sign(real(x)-xl)>0&&sign(real(x)-xr)<0&&
sign(imag(x)-yl)>0&&sign(imag(x)-yr)<0;
}
vec bnd[4];
ld calc1(vec st,vec arg){
if(!chkin(st))return 0;
ld len=INFINITY;
for(int i=0;i<4;i++){
for(vec x:common(bnd[i],bnd[(i+1)%4],st,st+arg)){
if(sign(dot(x-st,arg))>=0)len=min(len,abs(x-st));
}
}
return len;
}
ld calc2(vec a,vec b,vec arg){
return abs(calc1(a,arg)-calc1(b,arg));
}
ld calc(ld d,ld a){
ld w=sqrtl(a*a+4*d*d);
return w*a/4/d+d*log(a+w);
}
vector<ld> solve(ld a,ld b,ld c){
if(sign(a)==0){
if(sign(b)==0)return {};
else return {-c/b};
}
ld delta=b*b-4*a*c;
if(sign(delta)<0)return {};
delta=sqrtl(max<ld>(0,delta));
return {(-b-delta)/2/a,(-b+delta)/2/a};
}
ld calc3(vec p1,vec p2,vec o,vec L,vec R){
vec x=arg(p2-p1),y=x*vec(0,1);
if(sign(dot(y,o-p1))<0)y=-y;
ld d=dot(o-p1,y)/2,l=dot(L-o,x),r=dot(R-o,x);
// debug(p1,p2,o,L,R,l,r);
auto find=[&](ld p){
return p*x+p*p/4/d*y+o-y*d;
};
if(l>r)swap(l,r),swap(L,R);
vector<ld>t{l,r};
for(int xt:{xl,xr}){
for(ld p:solve(ld(1)/4/d*real(y),real(x),real(o-y*d)-xt)){
if(sign(p-l)>0&&sign(p-r)<0)t.push_back(p);
}
}
for(int yt:{yl,yr}){
for(ld p:solve(ld(1)/4/d*imag(y),imag(x),imag(o-y*d)-yt)){
if(sign(p-l)>0&&sign(p-r)<0)t.push_back(p);
}
}
sort(all(t));
ld res=0;
for(int i=1;i<t.size();i++){
ld tl=t[i-1],tr=t[i],mid=(tl+tr)/2;
if(chkin(find(mid)))res+=abs(calc(d,tr)-calc(d,tl));
}
return res;
}
vec c1,c2,c3,d1,d2,d3,d4,d5,d6,d7,d8,d9;
void work(){
scanf("%d%d%d%d",&xl,&yl,&xr,&yr);
bnd[0]=vec(xl,yl),bnd[1]=vec(xr,yl);
bnd[2]=vec(xr,yr),bnd[3]=vec(xl,yr);
read(a1),read(a2),read(b1),read(b2);
// debug(xl,yl,xr,yr);
// debug(a1,a2);
// debug(b1,b2);
if(sign(cross(a2-a1,b2-b1))!=0){
c1=common(a1,a2,b1,b2)[0];
c2=arg(b2-b1)+arg(a2-a1);
[&](){
ld mx=0;
for(int i=0;i<4;i++){
mx=max(mx,abs(dot(c2,a2-a1)));
int cnt=0;
for(vec x:{a1,a2,b1,b2}){
cnt+=sign(dot(x-c1,c2))>=0;
}
if(cnt==4)return;
c2*=vec(0,1);
}
for(int i=0;i<4;i++){
int cnt=0;
for(vec x:{a1,a2,b1,b2}){
cnt+=sign(dot(x-c1,c2))>=0;
}
if(cnt==3&&sign(mx-abs(dot(c2,a2-a1)))==0)return;
c2*=vec(0,1);
}
assert(0);
}();
}else{
c1=(a1+b1)/ld(2);
c2=a2-a1;
c1=c1-arg(c2)*ld(3e3);
}
auto cmp=[&](vec a,vec b){
return sign(dot(a-b,c2))<0;
};
if(cmp(a2,a1))swap(a1,a2);
if(cmp(b2,b1))swap(b1,b2);
if(cmp(b1,a1))swap(a1,b1),swap(a2,b2);
if(sign(cross(a2-a1,b2-b1))==0&&sign(cross(a2-a1,b1-a1))==0){
c1=(a2+b1)/ld(2);
ld ans=0;
ans+=calc1(c1,c2*vec(0,1));
ans+=calc1(c1,c2*vec(0,-1));
printf("%.15Lf\n",ans);
return;
}
// debug("c",c1,c2);
// debug("a",a1,a2);
// debug("b",b1,b2);
if(cmp(a2,b1)){
auto [st,arg]=midline(a2,b1);
if(sign(dot(arg,c2))<0)arg=-arg;
d1=common(st,st+arg,a2,a2+(a1-a2)*vec(0,1))[0];
d2=common(st,st+arg,b1,b1+(b2-b1)*vec(0,1))[0];
d7=arg;
}else{
d1=common(c1,c1+c2,b1,b1+(b2-b1)*vec(0,1))[0];
d2=common(c1,c1+c2,a2,a2+(a1-a2)*vec(0,1))[0];
d7=c2;
}
// debug("d1,d2",d1,d2);
ld ans=0;
ans+=calc2(d1,d2,d7);
// debug(ans);
ans+=calc3(b1,b2,a2,d2,b2);
// debug(ans);
auto [w1,w2]=midline(a2,b2);
if(sign(dot(w2,c2))<0)w2=-w2;
auto res=common(w1,w1+w2,b2,b2+(b1-b2)*vec(0,1));
// debug("w1,w2",w1,w2);
if(res.empty())res={w1};
d3=res[0];
ans+=calc1(d3,w2);
// debug(ans);
tie(w1,w2)=midline(a1,b1);
if(sign(dot(w2,c2))>0)w2=-w2;
res=common(w1,w1+w2,a1,a1+(a2-a1)*vec(0,1));
if(res.empty())res={w1};
d4=res[0];
// debug("d3,d4",d3,d4);
if(sign(dot(c2,a1-c1))<0){
d5=common(w1,w1+w2,b1,b1+(b2-b1)*vec(0,1))[0];
// debug(d4,d5);
c3=c2*vec(0,1);
if(sign(dot(c3,b2-b1))<0)c3=-c3;
d8=common(c1,c1+c3,b1,b1+(b2-b1)*vec(0,1))[0];
auto [w3,w4]=midline(a1,b2);
if(sign(dot(w4,c3))<0)w4=-w4;
d6=common(w3,w3+w4,b2,b2+(b1-b2)*vec(0,1))[0];
if(sign(dot(a2-a1,d4-d8))>=0){
ans+=calc3(a1,a2,b1,d1,d4);
ans+=calc2(d4,d5,w2);
ans+=calc3(b1,b2,a1,b1,b2);
ans+=calc1(d6,w4);
}else{
// debug("d8",d8);
// debug(ans);
ans+=calc3(a1,a2,b1,d1,d8);
d9=common(c1,c1+c3,b2,b2+(b1-b2)*vec(0,1))[0];
ans+=calc2(d8,d9,c3);
if(sign(dot(c3,a1-b2))>0){
d6=common(w3,w3+w4,a1,a1+(a2-a1)*vec(0,1))[0];
ans+=calc3(a1,a2,b2,d6,d9);
ans+=calc1(d6,w4);
}else{
ans+=calc3(b1,b2,a1,d9,d6);
ans+=calc1(d6,w4);
}
}
}else{
ans+=calc3(a1,a2,b1,d1,a1);
ans+=calc1(d4,w2);
}
printf("%.15Lf\n",ans);
}
int main(){
for(scanf("%d",&T);T--;)work();
return 0;
}
#ifdef DEBUG
#include"debug.hpp"
#endif
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3940kb
input:
1 0 0 7 6 2 4 4 4 3 2 5 2
output:
7.552593593868681
result:
ok found '7.552593594', expected '7.552593594', error '0.000000000'
Test #2:
score: -100
Wrong Answer
time: 325ms
memory: 3896kb
input:
100000 677 -490 687 -487 678 -488 681 -489 686 -488 679 -488 753 896 758 902 756 899 755 901 754 898 754 899 -786 69 -781 81 -784 75 -782 78 -784 71 -782 72 -879 110 -874 114 -878 111 -877 113 -877 112 -876 113 331 -97 340 -89 333 -92 337 -92 337 -90 332 -90 -26 -647 -22 -644 -23 -645 -24 -645 -25 -...
output:
5.756861965868622 6.008126807150707 5.355807136191452 4.629796182372577 9.158262808184446 5.124014274138828 3.000000000000000 17.058813475626220 1.783520657043467 8.589064533330053 6.943453694034834 4.117558803704212 4.421936941760152 8.164908200919798 9.776145361403313 3.080915944275567 8.952536893...
result:
wrong answer 8th numbers differ - expected: '15.7715198', found: '17.0588135', error = '0.0816214'