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湖南程序设计比赛,虽然路途遥远,六月的湘潭天气燥热,不过在一起的努力之下,拿到了一块铜牌,也算没空手而归啦.不过通过比赛,还是发现我们的差距,希望这几个月自己 ...
随机推荐
- SSH整合之spring整合struts2(续上)
一.项目结构 二.新建UserAction,继承自ActionSupport,并实现ModelDriven<User>接口:getModel方法是用来装配对象属性的:注意,userServ ...
- Protocol Buffers(Protobuf) 官方文档--Protobuf语言指南
Protocol Buffers(Protobuf) 官方文档--Protobuf语言指南 约定:为方便书写,ProtocolBuffers在下文中将已Protobuf代替. 本指南将向您描述如何使用 ...
- Java & C++ 大数计算
Java--大数计算,妈妈再也不用担心我的学习了 . BigInteger 英文API: http://docs.oracle.com/javase/8/docs/api/ 中文API: http:/ ...
- 在CentOS 7上利用systemctl添加自定义系统服务
每一个服务以.service结尾,一般会分为3部分:[Unit].[Service]和[Install],具体内容如下: [Unit]Description=*****After=network.ta ...
- 搭建SpringMVC+Mybatis框架并实现数据库的操作
User类 public class User { private Integer id; private String userName; private String password; priv ...
- WebBrowser 禁用右键
禁用错误脚本提示 将 WebBrowser控件的 ScriptErrorsSuppressed 设为 true 禁用右键菜单 将 WebBrowser 的 IsWebBrowserContextMen ...
- Xcode6中添加pch全局引用文件
前沿:xcode6中去掉了pch,为了一些琐碎的头文件引用,加快了 编译速度! xcode6添加pch文件方法 1. 右键Supporting File,选择“New File” 2. 选择Other ...
- mysql 的设置
网上的一些文章都已经比较老了,现在版本高了之后,其实配置是很省力的(不考虑什么负载的话) 分享全过程,出了文中提到的安装epel rpmfushion 源指令不同外,其他的过程也适用与Centos 5 ...
- centos6.4yum搭建lamp环境
1.配置防火墙,开启80端口.3306端口vi /etc/sysconfig/iptables-A INPUT -m state --state NEW -m tcp -p tcp --dport 8 ...
- 模式串匹配之KMP算法
模式串匹配之KMP算法 KMP算法 模式值计算(next[j]) (1) next[0]=-1, 第一个字符模式值为-1 (2) next[j]=-1, T中下标为j的字符与首字符相同,且j前面的1 ...