设为首页 加入收藏

TOP

UVA - 11437 - Triangle Fun (计算几何~)
2015-07-20 17:18:13 来源: 作者: 【 】 浏览:4
Tags:UVA 11437 Triangle Fun 计算 几何

UVA - 11437

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

?

Submit Status

Description

Download as PDF

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 x, A y, B x, B y, C x, C y. (0≤A x, A y, B x, B y, C x,C y ≤10000) in one line line. These six numbers denote that the coordinate of points A, B and C are (A x, A y), (B x, B y) and (C x, C y) 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 
  
   
#include 
   
     #include 
    
      #include 
     
       #include 
      
        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; } 
      
     
    
   
  

?

?

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇Leetcode_Partition List 下一篇[codevs 1789] 最大获利(2006年N..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·如何理解c语言指针和 (2025-12-27 01:19:11)
·为什么C标准库没有链 (2025-12-27 01:19:08)
·玩转C语言和数据结构 (2025-12-27 01:19:05)
·MySQL 基础入门视频 (2025-12-26 23:20:22)
·小白入门:MySQL超详 (2025-12-26 23:20:19)