UVA - 11437 - Triangle Fun (计算几何~)

UVA - 11437

Triangle Fun

Time Limit: 1000MS Memory Limit: Unknown 64bit IO Format: %lld & %llu

Submit Status

Description

Problem A

Triangle Fun

Input: Standard Input

Output: Standard Output

In the picture below you can see a triangle ABC. Point D, E and F divides the sides BC, CA and AB into ratio 1:2 respectively. That is CD=2BD, AE=2CE and BF=2AF. A, D; B, E and C, F are connected. AD and BE intersects at P, BE and CF intersects at Q and
CF and AD intersects at R.

So now a new triangle PQR is formed. Given triangle ABC your job is to find the area of triangle PQR.

Input

First line of the input file contains an integer N (0<N<1001) which denotes how many sets of inputs are there. Input for each set contains six floating-point number Ax, Ay, Bx, By, Cx, Cy.
(0≤Ax, Ay, Bx, By, Cx,Cy ≤10000) in one line line. These six numbers denote that the coordinate of points A, B and C are (Ax, Ay), (Bx, By) and (Cx,
Cy) respectively. A, B and C will never be collinear.

Output

For each set of input produce one line of output. This one line contains an integer AREA. Here AREA is the area of triangle PQR, rounded to the nearest integer.

Sample Input


2

3994.707 9251.677 4152.916 7157.810 5156.835 2551.972

6903.233 3540.932 5171.382 3708.015 213.959 2519.852

Output for Sample Input


98099

206144

 


Problemsetter: Shahriar Manzoor

Source

Root :: Prominent Problemsetters :: Shahriar Manzoor

Root :: Competitive Programming: Increasing the Lower Bound of Programming Contests (Steven & Felix Halim) :: Chapter 7. (Computational) Geometry :: Geometry Basics :: Triangles
(plus Circles)

Root :: AOAPC I: Beginning Algorithm Contests -- Training Guide (Rujia Liu) :: Chapter 4. Geometry :: Basic Problems

Root :: Competitive Programming 3: The New Lower Bound of Programming Contests (Steven & Felix Halim) :: (Computational) Geometry :: Basic Geometry :: Triangles
(plus Circles)

思路:先求出D,E,F,再根据线段相交得到P,Q,R,,利用叉积求得面积即可。。

AC代码:

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#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 - (Vector A, Vector 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); } 

bool operator < (const Point& a, const Point& b) {
	return a.x < b.x || (a.x == b.x && a.y < b.y);
} 

const double eps = 1e-10;
int dcmp(double x) {
	if(fabs(x) < eps) return 0; else return x < 0 ? -1 : 1;
}

bool operator == (const Point& a, const Point& b) {
	return dcmp(a.x - b.x) == 0 && dcmp(a.y - b.y) == 0;
}

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)); } 

double Cross(Vector A, Vector B) { return A.x*B.y - A.y*B.x; }
double Area2(Point A, Point B, Point C) { return Cross(B-A, C-A); }

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

Vector Normal(Vector A) {
    double L = Length(A);
    return Vector(-A.y/L, A.x/L);
}

Point GetLineIntersection(Point P, Vector v, Point Q, Vector w) {
	Vector u = P - Q;
	double t = Cross(w, u) / Cross(v, w);
	return P + v * t;
} 

double DistanceToLine(Point P, Point A, Point B) {
    Vector v1 = B-A, v2 = P - A;
    return fabs(Cross(v1,v2) / Length(v1));
}  

double DistanceToSegment(Point P, Point A, Point B) {
    if(A==B) return Length(P-A);
    Vector v1 = B - A, v2 = P - A, v3 = P - B;
    if(dcmp(Dot(v1, v2)) < 0) return Length(v2);
    else if(dcmp(Dot(v1, v3)) > 0) return Length(v3);
    else return fabs(Cross(v1, v2)) / Length(v1);
}  

Point GetLineProjection(Point P, Point A, Point B) {
	Vector v = B - A;
	return A + v * ( Dot(v, P-A) / Dot(v, v) );
}  

bool SegmentProperIntersection(Point a1, Point a2, Point b1, Point b2) {
	double c1 = Cross(a2 - a1, b1 - a1), c2 = Cross(a2 - a1, b2 - a1),
			c3 = Cross(b2 - b1, a1 - b1), c4 = Cross(b2 - b1, a2 - b1);
	return dcmp(c1) * dcmp(c2) < 0 && dcmp(c3) * dcmp(c4) < 0;
} 

bool OnSegment(Point p, Point a1, Point a2) {
	return dcmp(Cross(a1 - p, a2 - p)) == 0 && dcmp(Dot(a1 - p, a2 - p)) < 0;
} 

double ConvexPolygonArea(Point* p, int n) {
    double area = 0;
    for(int i = 1; i < n-1; i++)
        area += Cross(p[i] - p[0], p[i + 1] - p[0]);
    return area / 2;
}  

Point A, B, C, D, E, F, P, Q, R;

Point get_z(Point A, Point B) {
	Vector v = B - A;
	return A + v/3;
}

int main() {
	int N;
	scanf("%d", &N);
	while(N--) {
		scanf("%lf %lf %lf %lf %lf %lf", &A.x, &A.y, &B.x, &B.y, &C.x, &C.y);
		F = get_z(A, B); D = get_z(B, C); E = get_z(C, A);
		//printf("%lf %lf\n%lf %lf\n%lf %lf\n", F.x, F.y, D.x, D.y, E.x, E.y);
		P = GetLineIntersection(A, D-A, B, E-B);
		Q = GetLineIntersection(C, F-C, B, E-B);
		R = GetLineIntersection(A, D-A, C, F-C);
		double ans = Area2(P, Q, R) / 2;
		printf("%.0lf\n", ans);
	}
	return 0;
} 
时间: 2024-12-28 00:42:02

UVA - 11437 - Triangle Fun (计算几何~)的相关文章

UVA 11437 - Triangle Fun(计算几何)

这题只要根据题目,利用向量把点一个个求出来计算面积即可 不过据说有一种证明方法可以证明面积是1/7的原三角形 代码: #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> using namespace std; int t; struct Point { double x, y; Point() {} Point(double x, double y) { th

UVa 11437 - Triangle Fun

了解矢量为交点的坐标. #include <iostream> #include <cstring> #include <cstdio> #include <algorithm> #include <cstdlib> #include <cmath> #define eqs 1e-8 using namespace std; double a = 2.0/3; double b = 1.0/3; int main() { //freo

Triangle Fun UVA - 11437

Triangle Fun UVA - 11437 题意:给三角形,求一些三等分点,线段交点,求面积. 简单题~ 1 #include <bits/stdc++.h> 2 using namespace std; 3 const int inf = 0x3f3f3f3f; 4 const double eps = 1e-12; 5 const double pi = acos(-1.0); 6 7 struct Point { 8 double x,y; 9 Point (double x =

【UVA】11437 Triangle Fun(简单几何)

先求出在A,B,C上的三等分点在,这里使用向量运算进行加减就行了. 之后通过求出的三等分点 和 顶点的连线,求出3个交点. 最后用求出的三个交点算出面积. 注意:由于可能是钝角三角形,需要求其绝对值. 14116428 11437 Triangle Fun Accepted C++ 0.015 2014-08-30 03:27:36 #include <iostream> #include <cstdlib> #include <cstdio> #include <

UVA 11178-Morley&#39;s Theorem(计算几何_莫雷定理)

Problem D Morley's Theorem Input: Standard Input Output: Standard Output Morley's theorem states that that the lines trisecting the angles of an arbitrary plane triangle meet at the vertices of an equilateral triangle. For example in the figure below

UVA 11401 - Triangle Counting(数论+计数问题)

题目链接:11401 - Triangle Counting 题意:有1,2,3....n的边,求最多能组成的三角形个数. 思路:利用三角形不等式,设最大边为x,那么y + z > x 得 x - y < z < x 然后y取取值,可以从1取到x - 1,y为n时候,有n - 1个解,那么总和为0 + 1 + 2 +...+ (x - 2) = (x - 1) * ( x- 2) / 2; 然后扣除掉重复的y = z的情况,在y > x / 2时,每个y取值会出现一次y = z.

UVA - 11401 - Triangle Counting (递推!)

UVA - 11401 Triangle Counting Time Limit: 1000MS Memory Limit: Unknown 64bit IO Format: %lld & %llu Submit Status Description Problem G Triangle Counting Input: Standard Input Output: Standard Output You are given n rods of length 1, 2-, n. You have

uva 194 - Triangle(几何)

题目链接:uva 194 - Triangle 注意两边一角,并接角的对边确定时(即用正弦定理求解时,可能会有多解的情况) #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> using namespace std; const double pi = 4 * atan(1); const double eps = 1e-4; double A[6]; void

uva 11401 - Triangle Counting(数论)

题目链接:uva 11401 - Triangle Counting 题目大意:有多少种方法可以从1,2,3...n中选出3个不同的数组成三角形,给出n,求种数. 解题思路:加法原理,设最大边为x的三角形有c(x)个,那么另外两条边长分别为y和z,根据三角形的形式可以的y+z>x,所以z的范围即为x?y<z<x 根据这个不等式可以得到每个y值所对应的z值个数,为等差数列,所以 c(x)=(x?1)?(x?2)2??x?12?2 然后根据递推:f(n)=∑i=1nc(i) 代码 #incl