QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#503072 | #6831. Known as the Fruit Brother | wangyue2017 | WA | 1ms | 7984kb | C++17 | 3.0kb | 2024-08-03 16:13:01 | 2024-08-03 16:13:01 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define D double
#define P pair<D,D>
#define x first
#define y second
P operator-(const P&a,const P&b){
return {a.x-b.x,a.y-b.y};
}
P operator+(const P&a,const P&b){
return {a.x+b.x,a.y+b.y};
}
P operator*(const P&a,const D&b){
return {a.x*b,a.y*b};
}
D length(const P&a){
return sqrt(a.x*a.x+a.y*a.y);
}
D dist(const P&a,const P&b){
return length(a-b);
}
D cross(const P&a,const P&b){
return a.x*b.y-a.y*b.x;
}
D dot(P a,P b){
return a.x*b.x+a.y*b.y;
}
const int N =200000;
P d[N];
P barr[50][4];
int n,m,cnt;
D R;
void add_line(P p,P a,P b){
P v=b-a;
P pro=a+v*(dot(v,p-a)/dot(v,v));
if(dist(pro,p)>R)return;
D res=sqrt(R*R-dist(p,pro)*dist(p,pro));
d[++cnt]=pro+(b-a)*(1.0/dist(b,a))*res;
d[++cnt]=pro-(b-a)*(1.0/dist(b,a))*res;
}
void add_point(P d){
for(int i=1;i<=n;++i){
for(int j=0;j<=3;++j){
add_line(d,barr[i][j],barr[i][(j+1)%4]);
}
}
}
D dis[1000][1000];
void clac(int i,int j){
P a,b;
a=d[i],b=d[j];
if(i<=m){
if(dist(d[i],d[j])<=R){
dis[i][j]=0;
return;
}
else{
a=a+(b-a)*(1/length(b-a))*R;
}
}
for(int ii=1;ii<=n;++ii){
for(int jj=0;jj<=3;++jj){
if(cross(b-a,barr[ii][jj]-a)*(cross(b-a,barr[ii][(jj+1)%4]-a))<-1e-10
&&cross(a-barr[ii][jj],barr[ii][(jj+1)%4]-barr[ii][jj])*cross(b-barr[ii][jj],barr[ii][(jj+1)%4]-barr[ii][jj])<-1e-10){
dis[i][j]=1e30;
return;
}
}
}
dis[i][j]=dist(b,a);
}
D ans[N];
bool in[N];
int pre[N];
int main(){
cin>>n>>m>>R;
for(int i=1;i<=n;++i){
D x1,y1,x2,y2;
cin>>x1>>y1>>x2>>y2;
barr[i][0]={x1,y1};barr[i][1]={x1,y2};barr[i][2]={x2,y2};barr[i][3]={x2,y1};
}
for(int i=1;i<=m;++i){
D x,y;
cin>>x>>y;
d[++cnt]={x,y};
}
for(int i=1;i<=n;++i){
for(int j=0;j<=3;++j){
d[++cnt]=barr[i][j];
}
}
D xs,ys,xt,yt;
cin>>xs>>ys>>xt>>yt;
d[++cnt]={xs,ys},d[++cnt]={xt,yt};
int S=cnt-1,T=cnt;
for(int i=1;i<=m;++i){
add_point(d[i]);
}
for(int i=1;i<=cnt;++i){
for(int j=1;j<=cnt;++j){
if(i==j)continue;
clac(i,j);
}
}
for(int i=1;i<=cnt;++i)ans[i]=1e30;
priority_queue<pair<double,int>, vector<pair<double,int> >, greater<pair<double,int> > >q;
ans[S]=0;
q.push({0,S});
while(!q.empty()){
auto [d,u]= q.top(); q.pop();
if (in[u]) continue;
in[u] = 1;
for (int i = 1; i <= cnt; i++) {
if (ans[u] + dis[u][i] < ans[i]) {
ans[i] = ans[u] + dis[u][i];
pre[i]=u;
q.push({ans[i], i});
}
}
}
printf("%.9lf",ans[T]);
// cout<<ans[T];
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 7964kb
input:
1 2 2 0 2 7 4 -3 3 8 2 1 1 6 6
output:
9.543203767
result:
ok found '9.5432038', expected '9.5432038', error '0.0000000'
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 7984kb
input:
1 2 3 0 2 7 4 -1 4 8 2 1 1 6 6
output:
7.640554790
result:
wrong answer 1st numbers differ - expected: '7.9303914', found: '7.6405548', error = '0.0365476'