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


  计算几何,求直线交点,向量运算,求三角形面积

  这道题是计算几何基本知识的混合应用,用到了以上知识,但是都不难。思路是先用 “点 + 向量 = 点” 的原理,求出每一个边的三分点。然后求每一对三分线的交点即为所求三角形的三个顶点。最后求出三角形面积即可。

  需要注意的是,最后输出的时候要求是四舍五入(“rounded to”是四舍五入的意思)是取整数,所以要 +0.5 再强制转换为int(强制转换是直接砍掉小数点后的部位)。因为这个原因WA了两次,改正后才AC,唉,万恶的英语。

  代码:

 #include <iostream>
#include <cmath>
using namespace std;
#define eps 1e-10
/********** 定义点 **********/
struct Point{
double x,y;
Point(double x=,double y=):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 b)
{
return Vector(a.x*b,a.y*b);
}
/********** 向量 / 数 = 向量 **********/
Vector operator / (Vector a,double b)
{
return Vector(a.x/b,a.y/b);
}
/********** 2向量求叉积 **********/
double Cross(Vector a,Vector b)
{
return a.x*b.y-b.x*a.y;
}
/********** 3点求叉积 **********/
double Cross(Point a,Point b,Point c)
{
return (c.x-a.x)*(b.y-a.y) - (c.y-a.y)*(b.x-a.x);
}
/********** 直线交点 **********/
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;
}
int main()
{
int n;
cin>>n;
while(n--){
Point a,b,c;
cin>>a.x>>a.y>>b.x>>b.y>>c.x>>c.y;
Point d,e,f; //每边的三分点
d = b + (c-b)/;
e = c + (a-c)/;
f = a + (b-a)/;
Point p,q,r; //中间三角形的三顶点
p = GetLineIntersection(a,d-a,b,e-b);
q = GetLineIntersection(b,e-b,c,f-c);
r = GetLineIntersection(a,d-a,c,f-c);
cout<<int(fabs(Cross(p,q,r))/+0.5)<<endl;
}
return ;
}

Freecode : www.cnblogs.com/yym2013

UVa 11437:Triangle Fun(计算几何综合应用,求直线交点,向量运算,求三角形面积)的更多相关文章

  1. POJ_1269_Intersecting Lines_求直线交点

    POJ_1269_Intersecting Lines_求直线交点 Description We all know that a pair of distinct points on a plane ...

  2. 简单几何(求交点) UVA 11437 Triangle Fun

    题目传送门 题意:三角形三等分点连线组成的三角形面积 分析:入门题,先求三等分点,再求交点,最后求面积.还可以用梅涅劳斯定理来做 /********************************** ...

  3. UVA 11437 - Triangle Fun 向量几何

    http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...

  4. uva 11437 - Triangle Fun

    计算几何: 直线交点: #include<cstdio> using namespace std; struct node { double x,y; node(,):x(x),y(y){ ...

  5. Uva 11178 Morley's Theorem 向量旋转+求直线交点

    http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=9 题意: Morlery定理是这样的:作三角形ABC每个 ...

  6. hdu 2857:Mirror and Light(计算几何,点关于直线的对称点,求两线段交点坐标)

    Mirror and Light Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  7. poj 1269 Intersecting Lines——叉积求直线交点坐标

    题目:http://poj.org/problem?id=1269 相关知识: 叉积求面积:https://www.cnblogs.com/xiexinxinlove/p/3708147.html什么 ...

  8. [java作业]Fan、求直线交点、Triangle2D、选课

    public class Fan { public static void main(String[] args) { Fan fan1 = new Fan(), fan2 = new Fan(); ...

  9. 湖南程序设计竞赛赛题总结 XTU 1237 Magic Triangle(计算几何)

    这个月月初我们一行三人去湖南参加了ccpc湖南程序设计比赛,虽然路途遥远,六月的湘潭天气燥热,不过在一起的努力之下,拿到了一块铜牌,也算没空手而归啦.不过通过比赛,还是发现我们的差距,希望这几个月自己 ...

随机推荐

  1. sql-server数据库中利用触发器实现表与表之间的级联删除

    create trigger Delete_Student --创建一个触发器 on student instead of delete as declare @sno varchar() selec ...

  2. mvc 简单笔记

    ---恢复内容开始--- 入口文件 index.php 唯一的一个让浏览器直接请求的脚本文件 控制器 协调模型和试图 模型 提供数据 保存数据 数据的验证 试图 只负责显示 <?php $c = ...

  3. Java及Android开发环境搭建

    前言 自从接触java以来,配置环境变量折腾了好几次,也几次被搞得晕头转向,后来常常是上网查阅相关资料才解决.但是过一段时间后一些细节就会记不清了,当要在其他机子上配置时又得上网查或者查阅相关书籍,如 ...

  4. matlab学习笔记 bsxfun函数

    matlab学习笔记 bsxfun函数 最近总是遇到 bsxfun这个函数,前几次因为无关紧要只是大概看了一下函数体去对比结果,今天再一次遇见了这个函数,想想还是有必要掌握的,遂查了些资料总结如下. ...

  5. js 对象方法、类方法、原型方法的区别;私有属性、公有属性、公有静态属性的区别

    <html> <head> <meta http-equiv="Content-Type" content="text/html; char ...

  6. U盘10分钟安装linux系统

    说来可能不信,10分钟包括创建U盘启动盘,用U盘启动,安装,不联网,不更新,不安装语言包,等装好系统再更新. Windows系统硬盘分区 如果你用的是Windows系统,现有的硬盘没有未分配的空间,需 ...

  7. ubuntu查看版本命令

    有两种方法 1,cat /etc/issue 2,sudo lsb_release -a 这个查询出来的结果比上面的那个全一些.

  8. Entity Framework 关系约束配置

    前言 简单的说一下自己的理解,大家应该都很明白ADO.NET,也就是原生态的数据库操作,直接通过拼接SQL语句,表与表之间通过链接(inner join  left join  或者子查询),也就是在 ...

  9. #define 和typedef的区别

    typedef和define的详细区别 2011-04-19 15:11 firnow firnow 字号:T | T 对于都可以用来给对象取一个别名的Typedef和define来说,是有区别的.本 ...

  10. Populating Next Right Pointers in Each Node

    这题代码简单,不过不容易想到. void connect(TreeLinkNode *root) { if (root == nullptr ||root->left==nullptr)retu ...