QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#187412 | #3854. Radar | Nax_hueux# | WA | 0ms | 2272kb | C++14 | 3.8kb | 2023-09-24 17:04:24 | 2023-09-24 17:04:25 |
Judging History
answer
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cctype>
#define y0 _y0
#define y1 _y1
using namespace std;
inline int read(){
int x=0,f=0; char c=getchar();
while(!isdigit(c)) f|=c=='-',c=getchar();
while(isdigit(c)) x=x*10+(c^'0'),c=getchar();
return f?-x:x;
}
const int maxn=100010;
const double eps=1e-8;
int cir[maxn];
struct Point{
double x,y;
bool operator<(const Point &p)const{
return atan2(y,x)<atan2(p.y,p.x);
}
};
typedef Point Line;
inline double dot(Point p,Point q){ return p.x*q.x+p.y*q.y; }
inline double len(Point p){ return sqrt(dot(p,p)); }
inline double cross(Point p,Point q){ return p.x*q.y-p.y*q.x; }
Line line[maxn];
int R,F,N;
Line get1_line(double x,double y){
Line res=(Line){x,y};
int l=1,r=F;
while(l<r){
int mid=l+r+1>>1;
if(res<line[mid]) r=mid-1;
else l=mid;
}
if(l==1&&res<line[l]) return line[F];
return line[l];
}
Line get2_line(double x,double y){
Line res=(Line){x,y};
int l=1,r=F;
while(l<r){
int mid=l+r+1>>1;
if(res<line[mid]) r=mid-1;
else l=mid;
}
if(l<F) return line[l+1];
if(line[F]<res) return line[1];
return line[l];
}
int get1_cir(double r){
int p=lower_bound(cir+1,cir+R+1,r)-cir;
if(p>R) return cir[R];
return cir[p];
}
int get2_cir(double r){
int p=upper_bound(cir+1,cir+R+1,r)-cir-1;
if(p<=0) return cir[1];
return cir[p];
}
Point getp(double r,Line l){
// printf("getp %d (%.1lf, %.1lf)\n",r,l.x,l.y);
double x=l.x,y=l.y;
if(fabs(x)<1e-8){
if(y>0) return (Point){0,r};
else return (Point){0,-r};
}
if(x>0){
double xx=r*cos(atan(y/x)),yy=r*sin(atan(y/x));
// printf("= (%.2lf, %.2lf)\n",xx,yy);
return (Point){xx,yy};
} else{
double xx=-r*cos(atan(y/x)),yy=-r*sin(atan(y/x));
// printf("= (%.2lf, %.2lf)\n",xx,yy);
return (Point){xx,yy};
}
}
inline double getdis(Point p,Point q){
return sqrt((p.x-q.x)*(p.x-q.x)+(p.y-q.y)*(p.y-q.y));
}
int main(){
R=read(),F=read(),N=read();
for(int i=1;i<=R;i++) cir[i]=read();
sort(cir+1,cir+R+1);
for(int i=1;i<=F;i++) line[i].x=read(),line[i].y=read();
sort(line+1,line+F+1);
while(N--){
int x=read(),y=read();
Point p={x,y};
Line l1=get1_line(x,y),l2=get2_line(x,y);
if(fabs(l1.x-l2.x)<eps&&fabs(l1.y-l2.y)<eps){
double r=len(p)*dot(l1,p)/len(l1)/len(p);
int c1=get1_cir(r),c2=get2_cir(r);
Point p1=getp(c1,l1),p2=getp(c2,l1);
printf("%.12lf\n",min(getdis(p1,p),getdis(p2,p)));
} else{
if(cross(l1,l2)>0){
double r=len(p)*dot(l1,p)/len(l1)/len(p);
// printf("r = %.2lf\n",r);
int c1=get1_cir(r),c2=get2_cir(r);
Point p1=getp(c1,l1),p2=getp(c2,l1);
double _r=len(p)*dot(l2,p)/len(l2)/len(p);
int _c1=get1_cir(_r),_c2=get2_cir(_r);
Point p3=getp(_c1,l2),p4=getp(_c2,l2);
printf("%.12lf\n",min(min(min(getdis(p1,p),getdis(p2,p)),getdis(p3,p)),getdis(p4,p)));
} else{
double r=len(p)*dot(l1,p)/len(l1)/len(p);
// printf("r = %.2lf\n",r);
int c1=get1_cir(r),c2=get2_cir(r);
Point p1=getp(c1,l1),p2=getp(c2,l1);
if(r<0){
p1=p2={1000000000.0,1000000000.0};
}
double _r=len(p)*dot(l2,p)/len(l2)/len(p);
int _c1=get1_cir(_r),_c2=get2_cir(_r);
Point p3=getp(_c1,l2),p4=getp(_c2,l2);
if(_r<0){
p3=p4={1000000000.0,1000000000.0};
}
// printf("%.12lf\n",min(min(min(getdis(p1,p),getdis(p2,p)),getdis(p3,p)),getdis(p4,p)));
Point p5=getp(cir[1],l1),p6=getp(cir[1],l2);
printf("%.12lf\n",min(min(min(min(min(getdis(p1,p),getdis(p2,p)),getdis(p3,p)),getdis(p4,p)),getdis(p5,p)),getdis(p6,p)));
}
}
}
return 0;
}
/*
3 7 5
2
4
7
8 4
2 8
-1 5
-7 2
-4 -4
1 -8
6 -3
3 -1
8 1
2 6
-5 2
-1 -1
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 2264kb
input:
3 8 4 2 4 7 1 0 2 1 0 1 -1 1 -5 -2 -5 -6 -2 -7 6 -1 -1 -1 3 1 -5 -3 8 1
output:
0.605291072917 0.977772290466 1.551845105402 1.414213562373
result:
ok 4 numbers
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 2272kb
input:
1 8 32 7 0 1 1 0 0 -1 -1 0 1 -1 -1 1 -1 -1 1 1 20 10 10 20 -20 10 10 -20 -10 20 20 -10 -10 -20 -20 -10 2 1 1 2 -2 1 1 -2 -1 2 2 -1 -1 -2 -2 -1 5 0 0 5 -5 0 0 -5 5 5 5 -5 -5 5 -5 -5 9 0 0 9 -9 0 0 -9 9 9 9 -9 -9 9 -9 -9
output:
15.874985099258 15.874985099258 15.874985099258 15.874985099258 15.874985099258 15.874985099258 15.874985099258 16.401219466857 4.929656701046 4.929656701046 4.929656701046 4.929656701046 4.929656701046 4.929656701046 4.929656701046 5.099019513593 2.000000000000 2.000000000000 2.000000000000 2.00000...
result:
wrong answer 8th numbers differ - expected: '15.8749851', found: '16.4012195', error = '0.0331487'