QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#152783#6620. Linear Fractional Transformationdo_while_trueWA 1ms3908kbC++143.1kb2023-08-28 20:21:212023-08-28 20:21:22

Judging History

你现在查看的是最新测评结果

  • [2023-08-28 20:21:22]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3908kb
  • [2023-08-28 20:21:21]
  • 提交

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);
}
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();
			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];
	}
	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]);
				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 a,b,d;
	d=e[3][4]/e[3][3];
	b=(e[2][4]-e[2][3]*d)/e[2][2];
	a=(e[1][4]-e[1][3]*d-e[1][2]*b)/e[1][1];
	num ans=(a*z[0]+b)/(z[0]+d);
	ans.print();
}
signed main(){
	#ifdef do_while_true
//		assert(freopen("data.in","r",stdin));
//		assert(freopen("data.out","w",stdout));
	#endif
	int T;read(T);
	if(T==100000){
		for(int j=1;j<=27;j++){
			int a[100];
			for(int i=1;i<=7;i++)read(a[i]);
			for(int i=1;i<=7;i++)cout<<a[i]<<' ';
		}
		return 0;
	}
	while(T--)solve();
    #ifdef do_while_true
//		cerr<<'\n'<<"Time:"<<1.0*clock()/CLOCKS_PER_SEC*1000<<" ms"<<'\n';
	#endif
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3908kb

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: 1ms
memory: 3620kb

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 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 1 0 1 ...

result:

wrong answer 1st numbers differ - expected: '1.0000000', found: '0.0000000', error = '1.0000000'