【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 <string>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
using namespace std;
const double eps = 1e-10;
struct Point
{
	double x, y;
	Point(double x = 0, double y = 0) : x(x), y(y) { }
	bool operator < (const Point& a) const
	{
		if(a.x != x) return x < a.x;
		return y < a.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); }
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));
}
Point GetIntersection(Point P, Vector v, Point Q, Vector w)
{
	Vector u = P-Q;
	double t = Cross(w, u) / Cross(v, w);
	return P+v*t;
}
bool SegmentProperIntersection(Point a1, Point a2, Point b1, Point b2)
{
	double c1 = Cross(a2-a1, b1-a1), c2 = Cross(a2-a1, b2-a1);
	double c3 = Cross(b2-b1, a1-b1), c4 = Cross(b2-b1, a2-b1);
	return dcmp(c1) * dcmp(c2) < 0 && dcmp(c3) * dcmp(c4) < 0;
}
double PolygonArea(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;
}
bool OnSegment(Point p, Point a1, Point a2)
{
	return dcmp(Cross(a1-p, a2-p)) == 0 && dcmp(Dot(a1-p, a2-p)) < 0;
}
#define MAXD 50
int main(){
    int T;
    Point P[MAXD];
    scanf("%d",&T);
    while(T--){
        for(int i =  1 ; i <= 3 ; i++)
            scanf("%lf%lf",&P[i].x,&P[i].y);
        P[4].x = (2 * P[2].x + P[3].x) / 3;   //D
        P[4].y = (2 * P[2].y + P[3].y) / 3;
        P[5].x = (2 * P[3].x + P[1].x) / 3;   //E
        P[5].y = (2 * P[3].y + P[1].y) / 3;
        P[6].x = (2 * P[1].x + P[2].x) / 3;   //F
        P[6].y = (2 * P[1].y + P[2].y) / 3;
        Point a = GetIntersection(P[4],P[1] - P[4],P[5],P[2] - P[5]);
        //cout << a.x << " " << a.y << endl;
        Point b = GetIntersection(P[4],P[1] - P[4],P[6],P[3] - P[6]);
        //cout << b.x << " " << b.y << endl;
        Point c = GetIntersection(P[5],P[2] - P[5],P[6],P[3] - P[6]);
        //cout << c.x << " " << c.y << endl;
        double ans = Area2(a,b,c) / 2;
        ans = floor(ans + 0.5);
        printf("%.f\n",fabs(ans));
    }
    return 0;
}
时间: 2024-10-06 01:15:40

【UVA】11437 Triangle Fun(简单几何)的相关文章

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

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

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

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 11178 Morley&#39;s Theorem

题目传送门 题意:莫雷定理,求三个点的坐标 分析:训练指南P259,用到了求角度,向量旋转,求射线交点 /************************************************ * Author :Running_Time * Created Time :2015/10/21 星期三 15:56:27 * File Name :UVA_11178.cpp ************************************************/ #include

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

hdu5365 简单几何问题

http://acm.hdu.edu.cn/showproblem.php?pid=5365 Problem Description AFA is a girl who like runing.Today,he download an app about runing .The app can record the trace of her runing.AFA will start runing in the park.There are many chairs in the park,and

Python下opencv使用笔记(二)(简单几何图像绘制)

简单几何图像一般包括点.直线.矩阵.圆.椭圆.多边形等等.首先认识一下opencv对像素点的定义.图像的一个像素点有1或者3个值,对灰度图像有一个灰度值,对彩色图像有3个值组成一个像素值,他们表现出不同的颜色. 那么有了点才能组成各种多边形. (一)首先绘制直线 函数为:cv2.line(img,Point pt1,Point pt2,color,thickness=1,line_type=8 shift=0) 有值的代表有默认值,不用给也行.可以看到这个函数主要接受参数为两个点的坐标,线的颜色

UVa 11178 Morley&#39;s Theorem (几何问题)

题意:给定三角形的三个点,让你求它每个角的三等分线所交的顶点. 析:根据自己的以前的数学知识,应该很容易想到思想,比如D点,就是应该求直线BD和CD的交点, 以前还得自己算,现在计算机帮你算,更方便,主要注意的是旋转是顺时针还是逆时针,不要搞错了. 要求BD和CD就得先求那个夹角ABC和ACD,然后三等分. 代码如下: #include <iostream> #include <cstdio> #include <cstring> #include <cmath&