QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#152774 | #6620. Linear Fractional Transformation | do_while_true | WA | 170ms | 3940kb | C++14 | 3.1kb | 2023-08-28 20:13:20 | 2023-08-28 20:13:21 |
Judging History
answer
#include<cstdio>
#include<vector>
#include<queue>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<ctime>
#include<random>
#include<assert.h>
#define pb emplace_back
#define mp make_pair
#define fi first
#define se second
#define dbg(x) cerr<<"In Line "<< __LINE__<<" the "<<#x<<" = "<<x<<'\n'
#define dpi(x,y) cerr<<"In Line "<<__LINE__<<" the "<<#x<<" = "<<x<<" ; "<<"the "<<#y<<" = "<<y<<'\n'
#define DE(fmt,...) fprintf(stderr, "Line %d : " fmt "\n",__LINE__,##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int,int>pii;
typedef pair<ll,int>pli;
typedef pair<ll,ll>pll;
typedef pair<int,ll>pil;
typedef vector<int>vi;
typedef vector<ll>vll;
typedef vector<pii>vpii;
typedef vector<pll>vpll;
template<typename T>T cmax(T &x, T y){return x=x>y?x:y;}
template<typename T>T cmin(T &x, T y){return x=x<y?x:y;}
template<typename T>
T &read(T &r){
r=0;bool w=0;char ch=getchar();
while(ch<'0'||ch>'9')w=ch=='-'?1:0,ch=getchar();
while(ch>='0'&&ch<='9')r=r*10+(ch^48),ch=getchar();
return r=w?-r:r;
}
template<typename T1,typename... T2>
void read(T1 &x,T2& ...y){read(x);read(y...);}
const ld eps=1e-9;
struct num{
ld x,y;
void get(){
double u,v;
scanf("%lf%lf",&u,&v);
x=u;y=v;
}
void print(){
double u=x,v=y;
printf("%.15lf %.15lf\n",u,v);
}
num(ld u=0,ld v=0){x=u;y=v;}
}z[5],w[5],e[5][5];
bool operator==(const num &u,const num &v){return (abs(u.x-v.x)<=eps)&&(abs(u.y-v.y)<=eps);}
num operator+(const num &u,const num &v){return num(u.x+v.x,u.y+v.y);}
num operator-(const num &u,const num &v){return num(u.x-v.x,u.y-v.y);}
num operator*(const num &u,const num &v){
return num(u.x*v.x-u.y*v.y,u.x*v.y+u.y*v.x);
}
num operator/(const num &u,const num &v){
ld a=u.x,b=u.y;
ld c=v.x,d=v.y;
ld t=c*c+d*d;
return num((a*c+b*d)/t,(b*c-a*d)/t);
}
int p[5];
void solve(){
for(int i=1;i<=3;i++)z[i].get(),w[i].get();
z[0].get();
{
//c=0, d=1
num a=(w[1]-w[2])/(z[1]-z[2]);
num b=w[1]-a*z[1];
if(a*z[3]==w[3]){
num ans=a*z[0]+b;
ans.print();
// dbg(1);
return ;
}
}
//c=1
for(int i=1;i<=3;i++){
e[i][1]=z[i];
e[i][2]=num(1,0);
e[i][3]=num(0,0)-w[i];
e[i][4]=w[i]*z[i];
p[i]=i;
}
for(int i=1;i<=3;i++){
for(int j=i;j<=3;j++)
if(!(e[j][i]==num(0,0))){
swap(e[i],e[j]);
swap(p[i],p[j]);
break;
}
for(int j=i+1;j<=3;j++){
num o=e[j][i]/e[i][i];
for(int k=i;k<=4;k++)
e[j][k]=e[j][k]-(e[i][k]*o);
}
}
num v[4];
v[3]=e[3][4]/e[3][3];
v[2]=(e[2][4]-e[2][3]*v[3])/e[2][2];
v[1]=(e[1][4]-e[1][3]*v[3]-e[1][2]*v[2])/e[1][1];
num a,b,d;
for(int i=1;i<=3;i++){
if(p[i]==1)a=v[i];
else if(p[i]==2)b=v[i];
else d=v[i];
}
num ans=(a*z[0]+b)/(z[0]+d);
ans.print();
// dbg(2);
}
signed main(){
#ifdef do_while_true
assert(freopen("data.in","r",stdin));
// assert(freopen("data.out","w",stdout));
#endif
int T;read(T);
while(T--)solve();
#ifdef do_while_true
// cerr<<'\n'<<"Time:"<<1.0*clock()/CLOCKS_PER_SEC*1000<<" ms"<<'\n';
#endif
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3940kb
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: 170ms
memory: 3912kb
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 ...
result:
wrong answer 1st numbers differ - expected: '1.0000000', found: '-1.0000000', error = '2.0000000'