UVA - 11178 Morley's Theorem(几何,蓝书)

#include<cstdio>
#include<cmath>
using namespace std;

struct Point {
	double x, y;
	Point (double x=0, double y=0):x(x), y(y){}
};

typedef Point Vector;

Vector operator + (Vector A, Vector B){ return Vector(A.x+B.x, A.y+B.y); }
Vector operator - (Point A, Point B){ return Vector(A.x-B.x, A.y-B.y); }
Vector operator * (Vector A, double p){ return Vector(A.x*p, A.y*p); }
Vector operator / (Vector A, double p){ return Vector(A.x/p, A.y/p); }

Point read_point(){
	Point p;
	scanf("%lf%lf", &p.x, &p.y);
	return p;
}

double Dot(Vector A, Vector B){return A.x*B.x+A.y*B.y; } 
double Length(Vector A){ return sqrt(Dot(A, A)); }

double Angle(Vector A, Vector B){
	return acos(Dot(A, B)/Length(A)/Length(B));
}

Vector Rotate(Vector A, double rad){
	return Vector(A.x*cos(rad)-A.y*sin(rad), A.x*sin(rad)+A.y*cos(rad));
}

double Cross(Vector v1, Vector v2){
	return v1.x*v2.y-v1.y*v2.x;
}

Point GetLineIntersection(Point A, Vector v1, Point B, Vector v2){
	Vector v3=A-B;
	double t=Cross(v2, v3)/Cross(v1, v2);
	return A+v1*t;
}

Point getP(Point A, Point B, Point C){
	Vector v1=B-A;
	double a1=Angle(v1, C-A);
	v1=Rotate(v1, a1/3);
	
	Vector v2=A-B;
	double a2=Angle(v2, C-B);
	v2=Rotate(v2, -a2/3);
	
	return GetLineIntersection(A, v1, B, v2);
	
}

int main(){
	int T;
	scanf("%d", &T);
	
	while(T--){
		Point A, B, C, D, E, F;
		A=read_point();
		B=read_point();
		C=read_point();
		
		D=getP(B, C, A);
		E=getP(C, A, B);
		F=getP(A, B, C);
		printf("%.6lf %.6lf %.6lf %.6lf %.6lf %.6lf\n", D.x, D.y, E.x, E.y, F.x, F.y);
	}		
	
	return 0;
}

阅读更多

Lagrange's Four-Square Theorem

09-11

The fact that any positive integer has a representation as the sum of at most four positive squares (i.e. squares of positive integers) is known as Lagrange's Four-Square Theorem. The first published proof of the theorem was given by Joseph-Louis Lagrange in 1770. Your mission however is not to explain the original proof nor to discover a new proof but to show that the theorem holds for some specific numbers by counting how many such possible representations there are.nFor a given positive integer n, you should report the number of all representations of n as the sum of at most four positive squares. The order of addition does not matter, e.g. you should consider 4^2 + 3^2 and 3^2 + 4^2 are the same representation.nnFor example, let's check the case of 25. This integer has just three representations 1^2+2^2+2^2+4^2, 3^2 + 4^2, and 5^2. Thus you should report 3 in this case. Be careful not to count 4^2 + 3^2 and 3^2 + 4^2 separately.nnnInputnnThe input is composed of at most 255 lines, each containing a single positive integer less than 2^15, followed by a line containing a single zero. The last line is not a part of the input data.nnnOutputnnThe output should be composed of lines, each containing a single integer. No other characters should appear in the output.nnThe output integer corresponding to the input integer n is the number of all representations of n as the sum of at most four positive squares.nnnSample Inputnn1n25n2003n211n20007n0nnnSample Outputnn1n3n48n7n738

没有更多推荐了,返回首页