QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#43258 | #4497. Map | BobWang | AC ✓ | 1189ms | 3764kb | C++ | 2.3kb | 2022-08-08 17:06:49 | 2022-08-08 17:06:50 |
Judging History
answer
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize(2)
// #pragma GCC optimize(3)
// #pragma GCC optimize("inline")
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
inline long double read(){
long double x;
cin>>x;
return x;
}
inline void cmax(int &a,int b){a<b?a=b:0;}
inline void cmin(int &a,int b){a>b?a=b:0;}
struct P{
long double x,y;
inline friend P operator -(P &x,P &y){
return {x.x-y.x,x.y-y.y};
}
inline friend P operator +(P &x,P &y){
return {x.x+y.x,x.y+y.y};
}
inline friend long double operator *(P &x,P &y){
return {x.x*y.x+x.y*y.y};
}
inline friend P operator /(P &x,long double xx){
return {x.x/xx,x.y/xx};
}
};
inline long double sqr(long double x){
return x*x;
}
inline long double dis(const P &x,const P &y){
return sqrt(sqr(x.x-y.x)+sqr(x.y-y.y));
}
inline long double len(const P &x){
return sqrt(sqr(x.x)+sqr(x.y));
}
signed main(){
int T=read();
while(T--){
P A,B,C,D,a,b,c,d,AA,BB,CC,DD,aa,bb,cc,dd;
B.x=read(),B.y=read();
C.x=read(),C.y=read();
D.x=read(),D.y=read();
A.x=read(),A.y=read();
b.x=read(),b.y=read();
c.x=read(),c.y=read();
d.x=read(),d.y=read();
a.x=read(),a.y=read();
AA=A,BB=B,CC=C,DD=D;
aa=a,bb=b,cc=c,dd=d;
// cout<<bb.x<<" "<<bb.y<<" -- "<<endl;
P I=DD-AA,J=BB-AA,i=dd-aa,j=bb-aa;
I=I/len(I),J=J/len(J),i=i/len(i),j=j/len(j);
long double sigma=dis(AA,BB)/dis(aa,bb);
// cout<<sigma<<endl;
long double
p=sigma*i.x-I.x,
q=sigma*i.y-I.y,
r=sigma*j.x-J.x,
w=sigma*j.y-J.y,
xx=sigma*i.x*aa.x+sigma*i.y*aa.y-AA.x*I.x-AA.y*I.y,
yy=sigma*j.x*aa.x+sigma*j.y*aa.y-AA.x*J.x-AA.y*J.y;
if(fabs(r*q-p*w)<1e-6){
// printf("%.8Lf %.8Lf\n",A.x,A.y);
cout<<fixed<<setprecision(10)<<A.x<<" "<<A.y<<endl;
continue;
}
long double y=(r*xx-yy*p)/(r*q-p*w),
x=(yy*q-w*xx)/(r*q-p*w);
// printf("%.8Lf %.8Lf\n",x,y);
cout<<fixed<<setprecision(10)<<x<<" "<<y<<endl;
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1189ms
memory: 3764kb
input:
100000 0 5 15 5 15 0 0 0 3 2 9 5 10 3 4 0 -605 604 604 605 605 -604 -604 -605 569 -338 568 -337 569 -336 570 -337 -964 963 963 964 964 -963 -963 -964 -364 838 -365 839 -364 840 -363 839 -664 663 663 664 664 -663 -663 -664 -307 -424 -308 -423 -307 -422 -306 -423 -866 865 865 866 866 -865 -865 -866 12...
output:
6.0000000000 2.0000000000 568.8082644628 -336.2512396694 -364.2463692946 838.3760373444 -306.4503012048 -422.9126506024 119.4705542725 796.6091224018 426.6965648855 50.2398218830 -138.7016574586 -400.8552486188 190.8919117647 -43.8272058824 -392.4260230850 -700.8384050367 96.5101763908 624.641791044...
result:
ok 200000 numbers