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. Spring实战学习笔记之SpEL表达式

            在Spring XML配置文件中装配Bean的属性和构造参数都是静态的,而在运行期才知道装配的值,就可以使用SpEL实现         SpEL表达式的首要目标是通过计算获得某个值. ...

  2. shell的内建命令和外部命令

    shell的内建命令和外部命令 Shell执行的命令可以分为内建命令(built-in)和外部命令(external),前者是构建在shell内部:后者是一个独立的文件(可以是二进制文件,也可以是一个 ...

  3. [Asp.net Mvc]通过UrlHelper扩展为js,css静态文件添加版本号

    写在前面 在app中嵌入h5应用,最头疼的就是缓存的问题,比如你修改了一个样式,或者在js中添加了一个方法,发布之后,并没有更新,加载的仍是缓存里面的内容.这个时候就需要清理缓存才能解决.但又不想让w ...

  4. js返回上一步

    用按钮来链接返回上一步. <input type ="button" value="返回上一步" onclick="javascript:his ...

  5. jQuery1.11源码分析(7)-----jQuery一些基本的API

    这篇文章比较繁杂,主要就是把jQuery源码从上到下列出来,看我的注释就好了. jQuery源码对各种加载器做了处理. //阅读这个源码是请先了解一下概念,即时函数,工厂模式 (function( g ...

  6. Clover(资源管理器增强)

    Clover(资源管理器增强) 下载地址:http://www.orsoon.com/Soft/13157.html 功能: Windows Explorer 资源管理器的一个扩展,为其增加类似谷歌  ...

  7. 淘宝(阿里百川)手机客户端开发日记第六篇 Service详解(一)

    public abstract class Service; [API文档关于Service类的介绍] A Service is an application component representi ...

  8. [BZOJ3624][Apio2008]免费道路

    [BZOJ3624][Apio2008]免费道路 试题描述 输入 输出 输入示例 输出示例 数据规模及约定 见“输入”. 题解 第一步,先尽量加入 c = 1 的边,若未形成一个连通块,则得到必须加入 ...

  9. Ubuntu 16.04 安装 VMware-Workstation-12

    以前一直使用 Ubuntu + Virtaulbox ,最近测试了 VMware-Workstation-9,性能超过 Virtaulbox-4.2.x,下面是详细步骤: 1 首先准备一个Ubuntu ...

  10. FFT(1)

    FFT Complex struct complex{ double re,im; complex(double r,double i){re=r,im=i;} complex(){re=0.0,im ...