QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#233270 | #6620. Linear Fractional Transformation | extreme1228# | WA | 203ms | 3992kb | C++20 | 2.4kb | 2023-10-31 15:54:19 | 2023-10-31 15:54:20 |
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
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
d.x=1;d.y=0;
//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=0
c = (w2 - w1)/(w1*z1 -w2*z2);
b = w1*(c*z1+d);
if( b/(c*z3+d) == w3){
w0 = b/(c*z0 + d);
cout<<w0.x<< " "<<w0.y<<"\n";
return;
}
//a!=0
a =((w3 - w1)*(w1*z1 - w2*z2) - (w2 - w1)*(w1*z1 - w3*z3) ) / ((z1 -z2)*(w1*z1 - w3*z3) - (z1 - z3)*(w1*z1 - w2*z2));
c = (a*(z1-z2) + w2 - w1)/(w1*z1 - w2*z2);
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
*/
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3992kb
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: 203ms
memory: 3944kb
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:
1.000000000000000 1.666666666666667 -1.000000000000000 1.000000000000000 -1.500000000000000 -0.500000000000000 0.333333333333333 -0.666666666666667 -0.384615384615385 -0.923076923076923 -1.000000000000000 0.000000000000000 -1.500000000000000 0.500000000000000 -0.853658536585366 -0.317073170731707 -1...
result:
wrong output format Expected double, but "-nan" found