UVa 11437:Triangle Fun(计算几何综合应用,求直线交点,向量运算,求三角形面积)
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(计算几何综合应用,求直线交点,向量运算,求三角形面积)的更多相关文章
- POJ_1269_Intersecting Lines_求直线交点
POJ_1269_Intersecting Lines_求直线交点 Description We all know that a pair of distinct points on a plane ...
- 简单几何(求交点) UVA 11437 Triangle Fun
题目传送门 题意:三角形三等分点连线组成的三角形面积 分析:入门题,先求三等分点,再求交点,最后求面积.还可以用梅涅劳斯定理来做 /********************************** ...
- UVA 11437 - Triangle Fun 向量几何
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...
- uva 11437 - Triangle Fun
计算几何: 直线交点: #include<cstdio> using namespace std; struct node { double x,y; node(,):x(x),y(y){ ...
- Uva 11178 Morley's Theorem 向量旋转+求直线交点
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=9 题意: Morlery定理是这样的:作三角形ABC每个 ...
- hdu 2857:Mirror and Light(计算几何,点关于直线的对称点,求两线段交点坐标)
Mirror and Light Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- poj 1269 Intersecting Lines——叉积求直线交点坐标
题目:http://poj.org/problem?id=1269 相关知识: 叉积求面积:https://www.cnblogs.com/xiexinxinlove/p/3708147.html什么 ...
- [java作业]Fan、求直线交点、Triangle2D、选课
public class Fan { public static void main(String[] args) { Fan fan1 = new Fan(), fan2 = new Fan(); ...
- 湖南程序设计竞赛赛题总结 XTU 1237 Magic Triangle(计算几何)
这个月月初我们一行三人去湖南参加了ccpc湖南程序设计比赛,虽然路途遥远,六月的湘潭天气燥热,不过在一起的努力之下,拿到了一块铜牌,也算没空手而归啦.不过通过比赛,还是发现我们的差距,希望这几个月自己 ...
随机推荐
- ON THE EVOLUTION OF MACHINE LEARNING: FROM LINEAR MODELS TO NEURAL NETWORKS
ON THE EVOLUTION OF MACHINE LEARNING: FROM LINEAR MODELS TO NEURAL NETWORKS We recently interviewed ...
- html5浮动、等高、弹性盒模型
1px dashed虚线 box-sizing拯救了布局 1.inherit 继承父级 2.content-box(默认)-----这个盒子的边框.内边距 这2个值是不包括在width和height ...
- WPF 注册全局快捷键
.NET技术交流群 199281001 .欢迎加入. using System; using System.Collections.Generic; using System.Linq; using ...
- [转载]如何在Ubuntu上安装LAMP服务器系统
[2013年7月25日 51CTO外电头条]为何应该在Ubuntu上安装LAMP服务器?从事Web开发工作时,我更偏爱在不受干扰的情况下,在我那台计算机上的开发环境下进行开发.我宁愿所犯的错误大部分是 ...
- 用JSON-server模拟REST API(二) 动态数据
用JSON-server模拟REST API(二) 动态数据 上一篇演示了如何安装并运行 json server , 在这里将使用第三方库让模拟的数据更加丰满和实用. 目录: 使用动态数据 为什么选择 ...
- POJ 3274 Gold Balanced Lineup
Gold Balanced Lineup Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 10924 Accepted: 3244 ...
- 微信稳居Android App排行榜4月份国内榜首
根据某机构通过对Android样本访问行为的持续监测数据进行样本属性加权并根据iOS/Android用户调研数据建模推总得出中国移动互联网用户规模以及相应的用户结构数据显示,2015年4月份国内And ...
- dedecms删除没有文章的标签
要批量的删除织梦TAG标签,那我们就只能在数据库里做修改了. 登录数据库,在数据库里执行以下SQL语句: delete FROM dede_tagindex where typeid not in ( ...
- Java中的构造函数和重载
一.Java中的构造函数 构造函数是对象被创建时初始化对象的成员方法,它具有和它所在的类完全一样的名字.构造函数只能有入口参数,没有返回类型,因为一个类的构造方法的返回类就是类本身.构造函数定义后,创 ...
- 微信开发学习日记(八):7步看懂weiphp插件机制,核心目标是响应微信请求
又经过了几个小时的梳理.回顾,截至目前,终于对weiphp这个框架的机制搞明白了些.想要完全明白,自然还需要大把的时间.第1步: 配置微信公众号,http://weiphp.jiutianniao ...