Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

就是个线代的题,附代妈

Posted by KatrineYang at 2016-07-30 10:18:16 on Problem 3403
#include <iostream>
using namespace std;

long long int gcd(long long int a, long long int b){
	if(a == 0 && b == 0) return 0;
	if(a == 0) return b;
	if(b == 0) return a;
	if(a > b) return gcd(b, a%b);
	else return gcd(a, b%a);
}

bool gx(long long int *a, long long int *b){
	return (a[1]*b[2] == a[2]*b[1]) && (a[1]*b[3] == a[3]*b[1]) && (a[2]*b[3] == a[3]*b[2]);
}

long long int hls(long long int *a, long long int *b, long long int *c){
	return a[1]*b[2]*c[3] + b[1]*c[2]*a[3] + c[1]*a[2]*b[3] - a[3]*b[2]*c[1] - b[3]*c[2]*a[1] - c[3]*a[2]*b[1];
}

int main() {
	long long int a[4], b[4], c[4], d[4];
	char C;
	cin >> a[1] >> C >> a[2] >> C >> a[3];
	cin >> b[1] >> C >> b[2] >> C >> b[3];
	cin >> c[1] >> C >> c[2] >> C >> c[3];
	cin >> d[1] >> C >> d[2] >> C >> d[3];
	if(gx(a,b) && gx(a,c)){
		if(!gx(a,d)){
			cout << "impossible" << endl;
		}
		else{
			cout << "1:0:0" << endl;
		}
		return 0;
	}
	long long int y1 = hls(d,b,c), y2 = hls(a,d,c), y3 = hls(a,b,d);
	if(hls(a,b,c) != 0){

		if(y1 < 0 || y2 < 0 || y3 < 0){
			y1 = -y1, y2 = -y2, y3 = -y3;
		}
		if(y1 < 0 || y2 < 0 || y3 < 0){
			cout << "impossible" << endl;
		}
		else{
			long long int x1 = y1*(a[1]+a[2]+a[3]), x2 = y2*(b[1]+b[2]+b[3]), x3 = y3*(c[1]+c[2]+c[3]);
			long long int GCD = gcd(x3, gcd(x1,x2));
			if(GCD != 0) {
				x1 /= GCD, x2 /= GCD, x3 /= GCD;
			}
			cout << x1 << ':' << x2 << ':' << x3 << endl;
		}
		return 0;
	}
	if(y1 != 0 || y2 != 0 || y3 != 0){
		cout << "impossible" << endl;
		return 0;
	}
	//如果x3=0
	if(a[1]*b[2] != a[2]*b[1]){
		long long int x1 = (d[1]*b[2]-d[2]*b[1]), x2 = (a[1]*d[2]-a[2]*d[1]);
		if(x1 < 0){
			x1 = -x1;
			x2 = -x2;
		}
		if(x1>=0 && x2>=0 && a[3]*x1+b[3]*x2==d[3]*(a[1]*b[2]-a[2]*b[1])){
			x1*=(a[1]+a[2]+a[3]);
			x2*=(b[1]+b[2]+b[3]);
			long long int GCD = gcd(x1,x2);
			x1 /= GCD, x2 /= GCD;
			cout << x1 << ':' << x2 << ':' << 0 << endl;
			return 0;
		}
	}
	if(a[1]*b[3] != a[3]*b[1]){
			long long int x1 = (d[1]*b[3]-d[3]*b[1]), x2 = (a[1]*d[3]-a[3]*d[1]);
			if(x1 < 0){
				x1 = -x1;
				x2 = -x2;
			}
			if(x1>=0 && x2>=0 && a[2]*x1+b[2]*x2==d[2]*(a[1]*b[3]-a[3]*b[1])){
				x1*=(a[1]+a[2]+a[3]);
				x2*=(b[1]+b[2]+b[3]);
				long long int GCD = gcd(x1,x2);
				x1 /= GCD, x2 /= GCD;
				cout << x1 << ':' << x2 << ':' << 0 << endl;
				return 0;
			}
		}
	if(a[3]*b[2] != a[2]*b[3]){
			long long int x1 = (d[2]*b[3]-d[3]*b[2]), x2 = (a[2]*d[3]-a[3]*d[2]);
			if(x1 < 0){
				x1 = -x1;
				x2 = -x2;
			}
			if(x1>=0 && x2>=0 && a[1]*x1+b[1]*x2==d[1]*(a[2]*b[3]-a[3]*b[2])){
				x1*=(a[1]+a[2]+a[3]);
				x2*=(b[1]+b[2]+b[3]);
				long long int GCD = gcd(x1,x2);
				x1 /= GCD, x2 /= GCD;
				cout << x1 << ':' << x2 << ':' << 0 << endl;
				return 0;
			}
		}


	//x2=0
	if(a[1]*c[2] != a[2]*c[1]){
			long long int x1 = (d[1]*c[2]-d[2]*c[1]), x2 = (a[1]*d[2]-a[2]*d[1]);
			if(x1 < 0){
				x1 = -x1;
				x2 = -x2;
			}
			if(x1>=0 && x2>=0 && a[3]*x1+c[3]*x2==d[3]*(a[1]*c[2]-a[2]*c[1])){
				x1*=(a[1]+a[2]+a[3]);
				x2*=(c[1]+c[2]+c[3]);
				long long int GCD = gcd(x1,x2);
				x1 /= GCD, x2 /= GCD;
				cout << x1 << ':' << 0 << ':' << x2 << endl;
				return 0;
			}
		}
		if(a[1]*c[3] != a[3]*c[1]){
				long long int x1 = (d[1]*c[3]-d[3]*c[1]), x2 = (a[1]*d[3]-a[3]*d[1]);
				if(x1 < 0){
					x1 = -x1;
					x2 = -x2;
				}
				if(x1>=0 && x2>=0 && a[2]*x1+c[2]*x2==d[2]*(a[1]*c[3]-a[3]*c[1])){
					x1*=(a[1]+a[2]+a[3]);
					x2*=(c[1]+c[2]+c[3]);
					long long int GCD = gcd(x1,x2);
					x1 /= GCD, x2 /= GCD;
					cout << x1 << ':' << 0 << ':' << x2 << endl;
					return 0;
				}
			}
		if(a[3]*c[2] != a[2]*c[3]){
				long long int x1 = (d[2]*c[3]-d[3]*c[2]), x2 = (a[2]*d[3]-a[3]*d[2]);
				if(x1 < 0){
					x1 = -x1;
					x2 = -x2;
				}
				if(x1>=0 && x2>=0 && a[1]*x1+c[1]*x2==d[1]*(a[2]*c[3]-a[3]*c[2])){
					x1*=(a[1]+a[2]+a[3]);
					x2*=(c[1]+c[2]+c[3]);
					long long int GCD = gcd(x1,x2);
					x1 /= GCD, x2 /= GCD;
					cout << x1 << ':' << 0 << ':' << x2 << endl;
					return 0;
				}
			}





		//x1=0
		if(b[1]*c[2] != b[2]*c[1]){
				long long int x1 = (d[1]*c[2]-d[2]*c[1]), x2 = (b[1]*d[2]-b[2]*d[1]);
				if(x1 < 0){
					x1 = -x1;
					x2 = -x2;
				}
				if(x1>=0 && x2>=0 && b[3]*x1+c[3]*x2==d[3]*(b[1]*c[2]-b[2]*c[1])){
					x1*=(b[1]+b[2]+b[3]);
					x2*=(c[1]+c[2]+c[3]);
					long long int GCD = gcd(x1,x2);
					x1 /= GCD, x2 /= GCD;
					cout << 0 << ':' << x1 << ':' << x2 << endl;
					return 0;
				}
			}
			if(b[1]*c[3] != b[3]*c[1]){
					long long int x1 = (d[1]*c[3]-d[3]*c[1]), x2 = (b[1]*d[3]-b[3]*d[1]);
					if(x1 < 0){
						x1 = -x1;
						x2 = -x2;
					}
					if(x1>=0 && x2>=0 && b[2]*x1+c[2]*x2==d[2]*(b[1]*c[3]-b[3]*c[1])){
						x1*=(b[1]+b[2]+b[3]);
						x2*=(c[1]+c[2]+c[3]);
						long long int GCD = gcd(x1,x2);
						x1 /= GCD, x2 /= GCD;
						cout << 0 << ':' << x1 << ':' << x2 << endl;
						return 0;
					}
				}
			if(b[3]*c[2] != b[2]*c[3]){
					long long int x1 = (d[2]*c[3]-d[3]*c[2]), x2 = (b[2]*d[3]-b[3]*d[2]);
					if(x1 < 0){
						x1 = -x1;
						x2 = -x2;
					}
					if(x1>=0 && x2>=0 && b[1]*x1+c[1]*x2==d[1]*(b[2]*c[3]-b[3]*c[2])){
						x1*=(b[1]+b[2]+b[3]);
						x2*=(c[1]+c[2]+c[3]);
						long long int GCD = gcd(x1,x2);
						x1 /= GCD, x2 /= GCD;
						cout << 0 << ':' << x1 << ':' << x2 << endl;
						return 0;
					}
				}
			cout << "impossible" << endl;
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator