QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#687019 | #6620. Linear Fractional Transformation | Y_J_Y | WA | 219ms | 16240kb | C++20 | 2.5kb | 2024-10-29 16:47:59 | 2024-10-29 16:47:59 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define root 1,n,1
#define ls (rt<<1)
#define rs (rt<<1|1)
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define pd __gnu_pbds
inline ll read() {
ll x=0,w=1;char ch=getchar();
for(;ch>'9'||ch<'0';ch=getchar()) if(ch=='-') w=-1;
for(;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
return x*w;
}
inline void print(__int128 x){
if(x<0) {putchar('-');x=-x;}
if(x>9) print(x/10);
putchar(x%10+'0');
}
#define maxn 1000010
const double eps=1e-8;
#define int_INF 0x3f3f3f3f
#define ll_INF 0x3f3f3f3f3f3f3f3f
complex<long double>a[200][200];
int n;
int gauss() {
int c,r;
for(c=0,r=0;c<n;c++) {
int t=r;
for(int i=r;i<n;i++) {
if(abs(a[i][c])>abs(a[t][c])) {
t=i;
}
}
if(abs(a[t][c])<eps) continue;
for(int i=c;i<=n;i++) swap(a[t][i],a[r][i]);
for(int i=n;i>=c;i--) a[r][i]/=a[r][c];
for(int i=r+1;i<n;i++) {
if(abs(a[i][c])>eps) {
for(int j=n;j>=c;j--) {
a[i][j]-=a[r][j]*a[i][c];
}
}
}
r++;
}
if(r<n) {
for(int i=r;i<n;i++) {
if(abs(a[i][n])>eps) {
return 2;//无解
}
}
return 1;//有无穷多解
}
for(int i=n-1;i>=0;i--) {
for(int j=i+1;j<n;j++) {
a[i][n]-=a[i][j]*a[j][n];
}
}
return 0;//有唯一解
}
complex<long double>z[maxn],w[maxn];
long double p[maxn],q[maxn],r[maxn],s[maxn];
int main() {
int T=read();
while(T--) {
n=3;
for(int i=1;i<=3;i++) {
scanf("%Lf%Lf%Lf%Lf",&p[i],&q[i],&r[i],&s[i]);
z[i].real(p[i]);z[i].imag(q[i]);
w[i].real(r[i]);w[i].imag(s[i]);
}
scanf("%Lf%Lf",&p[4],&q[4]);
z[4].real(p[4]);z[4].imag(q[4]);
complex<long double>A=(w[1]-w[2])/(z[1]-z[2]);
complex<long double>B=w[1]-A*z[1];
if(abs(A*z[3]+B-w[3])<eps) {//意味着此时c=0
complex<long double>ans=A*z[4]+B;
printf("%.7Lf %.7Lf\n",ans.real(),ans.imag());
continue;
}
for(int i=0;i<3;i++) {
a[i][0]={1,0};a[i][1]={1,0};
a[i][2]=-w[i+1];
a[i][3]=w[i+1]*z[i+1];
}
int state=gauss();
// cout<<state<<endl;
complex<long double>ans=(a[0][3]+a[1][3])/(z[4]+a[2][3]);
printf("%.7Lf %.7Lf\n",ans.real(),ans.imag());
// cout<<a[2][3].real()<<" "<<a[2][3].imag()<<endl;
// cout<<"check:"<<endl;
// ans=(a[0][3]+a[1][3])/(z[1]+a[2][3]);
// printf("%.7Lf %.7Lf\n",ans.real(),ans.imag());
//
// ans=(a[0][3]+a[1][3])/(z[2]+a[2][3]);
// printf("%.7Lf %.7Lf\n",ans.real(),ans.imag());
//
// ans=(a[0][3]+a[1][3])/(z[3]+a[2][3]);
// printf("%.7Lf %.7Lf\n",ans.real(),ans.imag());
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 16240kb
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.0000000 0.0000000 0.0000000 1.0000000
result:
ok 4 numbers
Test #2:
score: -100
Wrong Answer
time: 219ms
memory: 14128kb
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:
0.1538462 0.2307692 -0.5000000 -0.5000000 0.3333333 -0.3333333 -0.3529412 -0.4117647 -0.6666667 -0.3333333 -0.7500000 0.5000000 -0.6000000 -0.8000000 0.3750000 -0.1250000 -0.2500000 1.2500000 0.4000000 -0.2000000 0.3846154 -0.0769231 -0.2800000 -0.0400000 -0.1538462 0.2307692 -0.0769231 -0.3846154 -...
result:
wrong answer 1st numbers differ - expected: '1.0000000', found: '0.1538462', error = '0.8461538'