QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#233242 | #6620. Linear Fractional Transformation | extreme1228# | WA | 208ms | 3876kb | C++20 | 2.4kb | 2023-10-31 15:32:47 | 2023-10-31 15:32:48 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
struct com{
double x,y;
friend com operator +(const com&a,const com&b){
com c;
c.x = a.x + b.x;
c.y = a.y + b.y;
return c;
}
friend com operator -(const com&a,const com&b){
com c;
c.x = a.x - b.x;
c.y = a.y - b.y;
return c;
}
friend com operator *(const com&a,const com&b){
com c;
c.x = a.x*b.x - a.y*b.y;
c.y = a.y*b.x + a.x*b.y;
return c;
}
friend com operator /(const com&a,const com&b){
com c;
c.x = (a.x*b.x + a.y*b.y)/(b.x*b.x + b.y*b.y);
c.y = (-a.x*b.y+a.y*b.x)/(b.x*b.x + b.y*b.y);
return c;
}
friend bool operator ==(const com&a,const com&b){
return fabs(a.x-b.x)<1e-7 && fabs(a.y-b.y)<1e-7;
}
};
void solve()
{
com z1,z2,z3,w1,w2,w3,z0,w0;
cin>>z1.x>>z1.y>>w1.x>>w1.y;
cin>>z2.x>>z2.y>>w2.x>>w2.y;
cin>>z3.x>>z3.y>>w3.x>>w3.y;
cin>>z0.x>>z0.y;
com a,b,c,d;
//d=0 c!=0 -> c=1 // (az+b)/z 此时不能有z为0
bool ok = 1;
if(z1.x==0 && z1.y==0){
ok=0;
}
if(z2.x==0 && z2.y==0){
ok=0;
}
if(z3.x==0 && z3.y==0){
ok=0;
}
if(ok){
a = (w1*z1 - w2*z2)/(z1-z2);
b = w1*z1 - a*z1;
if((a*z3 + b)/z3== w3){
w0 = (a*z0+b)/z0;
cout<<w0.x<< " "<<w0.y<<"\n";
return;
}
}
//d!=0 -> d=1
//c=0
a = (w1-w2)/(z1-z2);
b = w1-a*z1;
if((a*z3 + b) == w3){
w0 = a*z0+b;
cout<<w0.x<< " "<<w0.y<<"\n";
return;
}
//c!=0
a =((w3 - w1)*(w1*z1 - w2*z2) - (w2 - w1)*(w1*z1 - w3*z3) ) / ((z1 -z2)*(w1*z1 - w3*z3) - (z1 - z3)*(w1*z2 - w2*z1));
c = (a*(z1-z2) + w2 - w1)/(w1*z1 - w2*z2);
d.x=1;d.y=0;
b = w1*(c*z1+d)- a*z1;
w0 = (a*z0 + b)/(c*z0 + d);
cout<<w0.x<<" "<<w0.y<<"\n";
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t = 1;
cin>>t;
cout<<fixed<<setprecision(15);
while(t--){
solve();
}
return 0;
}
/*
2
-1 0 0 -1
0 1 -1 0
1 0 0 1
0 -1
-1 0 -1 0
0 1 0 -1
1 0 1 0
0 -1
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3876kb
input:
2 -1 0 0 -1 0 1 -1 0 1 0 0 1 0 -1 -1 0 -1 0 0 1 0 -1 1 0 1 0 0 -1
output:
1.000000000000000 0.000000000000000 0.000000000000000 1.000000000000000
result:
ok 4 numbers
Test #2:
score: -100
Wrong Answer
time: 208ms
memory: 3824kb
input:
100000 0 0 -1 1 1 1 1 0 1 0 1 -1 -1 0 -1 -1 -1 1 1 -1 1 -1 -1 0 1 0 -1 -1 -1 -1 0 -1 -1 1 -1 -1 0 -1 0 0 1 1 1 0 0 -1 0 0 0 0 -1 -1 1 0 1 1 -1 -1 0 -1 0 1 1 -1 1 0 -1 -1 1 -1 0 1 1 -1 1 0 1 0 0 -1 0 1 -1 -1 1 1 -1 1 0 0 -1 -1 0 1 0 1 1 0 1 1 1 -1 0 1 -1 -1 1 0 -1 0 1 -1 1 0 -1 1 -1 -1 1 0 0 -1 0 1 0...
output:
-nan -nan -1.000000000000000 1.000000000000000 -0.807692307692307 -1.038461538461539 0.200000000000000 -1.400000000000000 -0.029585798816568 -1.928994082840237 0.135135135135135 1.189189189189189 -1.500000000000000 -0.500000000000000 -0.522123893805310 0.168141592920354 -0.241379310344828 0.10344827...
result:
wrong output format Expected double, but "-nan" found