题目传送门

题意:三角形三等分点连线组成的三角形面积

分析:入门题,先求三等分点,再求交点,最后求面积。还可以用梅涅劳斯定理来做

/************************************************
* Author :Running_Time
* Created Time :2015/10/22 星期四 12:55:27
* File Name :UVA_11437.cpp
************************************************/ #include <cstdio>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <bitset>
#include <cstdlib>
#include <ctime>
using namespace std; #define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
typedef long long ll;
const int N = 1e5 + 10;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const double EPS = 1e-10;
struct Point { //点的定义
double x, y;
Point (double x=0, double y=0) : x (x), y (y) {}
};
typedef Point Vector; //向量的定义
Point read_point(void) { //点的读入
double x, y;
scanf ("%lf%lf", &x, &y);
return Point (x, y);
}
double polar_angle(Vector A) { //向量极角
return atan2 (A.y, A.x);
}
double dot(Vector A, Vector B) { //向量点积
return A.x * B.x + A.y * B.y;
}
double cross(Vector A, Vector B) { //向量叉积
return A.x * B.y - A.y * B.x;
}
int dcmp(double x) { //三态函数,减少精度问题
if (fabs (x) < EPS) return 0;
else return x < 0 ? -1 : 1;
}
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);
}
bool operator == (const Point &a, const Point &b) { //判断同一个点
return dcmp (a.x - b.x) == 0 && dcmp (a.y - b.y) == 0;
}
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 area_triangle(Point a, Point b, Point c) { //三角形面积,叉积
return fabs (cross (b - a, c - a)) / 2.0;
}
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 nomal(Vector A) { //向量的单位法向量
double len = length (A);
return Vector (-A.y / len, A.x / len);
}
Point point_inter(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 dis_to_line(Point p, Point a, Point b) { //点到直线的距离,两点式
Vector V1 = b - a, V2 = p - a;
return fabs (cross (V1, V2)) / length (V1);
}
double dis_to_seg(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 point_proj(Point p, Point a, Point b) { //点在直线上的投影,两点式
Vector V = b - a;
return a + V * (dot (V, p - a) / dot (V, V));
}
bool inter(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 on_seg(Point p, Point a1, Point a2) { //判断点在线段上,两点式
return dcmp (cross (a1 - p, a2 - p)) == 0 && dcmp (dot (a1 - p, a2 - p)) < 0;
}
double area_poly(Point *p, int n) { //多边形面积
double ret = 0;
for (int i=1; i<n-1; ++i) {
ret += fabs (cross (p[i] - p[0], p[i+1] - p[0]));
}
return ret / 2;
} Point get_point(Point a, Point b) {
return a + (b - a) / 3.0;
} int main(void) {
Point a, b, c, d, e, f, p, q, r;
Vector ad, cf, be;
int n; scanf ("%d", &n);
while (n--) {
a = read_point ();
b = read_point ();
c = read_point ();
d = get_point (b, c);
e = get_point (c, a);
f = get_point (a, b);
ad = d - a;
cf = f - c;
be = e - b;
p = point_inter (a, ad, b, be);
q = point_inter (b, be, c, cf);
r = point_inter (a, ad, c, cf);
printf ("%.0f\n", area_triangle (p, q, r));
} return 0;
}

  

简单几何(求交点) UVA 11437 Triangle Fun的更多相关文章

  1. 简单几何(求交点) UVA 11178 Morley's Theorem

    题目传送门 题意:莫雷定理,求三个点的坐标 分析:训练指南P259,用到了求角度,向量旋转,求射线交点 /*********************************************** ...

  2. Codeforces 935 简单几何求圆心 DP快速幂求与逆元

    A #include <bits/stdc++.h> #define PI acos(-1.0) #define mem(a,b) memset((a),b,sizeof(a)) #def ...

  3. 简单几何(求划分区域) LA 3263 That Nice Euler Circuit

    题目传送门 题意:一笔画,问该图形将平面分成多少个区域 分析:训练指南P260,欧拉定理:平面图定点数V,边数E,面数F,则V + F - E =  2.那么找出新增的点和边就可以了.用到了判断线段相 ...

  4. UVa 11437:Triangle Fun(计算几何综合应用,求直线交点,向量运算,求三角形面积)

    Problem ATriangle Fun Input: Standard Input Output: Standard Output In the picture below you can see ...

  5. UVA 11437 - Triangle Fun 向量几何

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

  6. 简单几何(数学公式+凸包) UVA 11168 Airport

    题目传送门 题意:找一条直线,使得其余的点都在直线的同一侧,而且使得到直线的平均距离最短. 分析:训练指南P274,先求凸包,如果每条边都算一边的话,是O (n ^ 2),然而根据公式知直线一般式为A ...

  7. 简单几何(求凸包点数) POJ 1228 Grandpa's Estate

    题目传送门 题意:判断一些点的凸包能否唯一确定 分析:如果凸包边上没有其他点,那么边想象成橡皮筋,可以往外拖动,这不是唯一确定的.还有求凸包的点数<=2的情况一定不能确定. /********* ...

  8. 简单几何(四边形形状) UVA 11800 Determine the Shape

    题目传送门 题意:给了四个点,判断能构成什么图形,有优先规则 分析:正方形和矩形按照点积为0和长度判断,菱形和平行四边形按向量相等和长度判断,梯形按照叉积为0判平行.因为四个点是任意给出的,首先要进行 ...

  9. uva 11437 - Triangle Fun

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

随机推荐

  1. java笔记--使用线程池优化多线程编程

    使用线程池优化多线程编程 认识线程池 在Java中,所有的对象都是需要通过new操作符来创建的,如果创建大量短生命周期的对象,将会使得整个程序的性能非常的低下.这种时候就需要用到了池的技术,比如数据库 ...

  2. 破解TP-Link路由-嗅探PPPoE拨号密码

    如果你平时都使用路由器直接上网,那么你还记得你的宽带(ADSL)帐户名和密码吗?忘记密码后又该如何找回呢?别急,本文带你一同找回遗忘的ADSL密码.1.安全性较差的路由器(例如腾达的某些路由器):这里 ...

  3. HDU 1707 简单模拟 Spring-outing Decision

    Spring-outing Decision Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/O ...

  4. Linux 命令行生成随机密码的十种方法

    Linux操作系统的一大优点是对于同样一件事情,你可以使用高达数百种方法来实现它.例如,你可以通过数十种方法来生成随机密码.本文将介绍生成随机密码的十种方法.这些方法均收集于Command-Line ...

  5. PhpStorm主题

    图的github仓库有很多编辑器的主题,jetbrains目录下都是PhpStorm支持的主题 1.到http://daylerees.github.io/预览各个主题的风格,找到自己喜欢的: 2.在 ...

  6. TCP中 recv和sendf函数

    recv和send函数: #include<sys/socket.h> ssize_t recv(int sockfd, void *buff, size_t nbytes, int fl ...

  7. Solr DIH导入出现 Data Config problem: 前言中不允许有内容 异常

    Solr配置DIH导入时出现 “Data Config problem: 前言中不允许有内容.” 异常. <response> <lst name="responseHea ...

  8. 使用JS构建简单Map(转)

    转载自:http://freejvm.iteye.com/blog/768025 最近使用源生的js处理页面数据,所谓源生的就是指没有经过包装的.最基本的JavaScript代码: 像使用ext,jQ ...

  9. Linux配置SSH公钥认证与Jenkins远程登录进行自动发布

    公钥认证,是使用一对加密字符串,一个称为公钥(public key), 任何人都可以看到其内容,用于加密:另一个称为密钥(private key),只有拥有者才能看到,用于解密. 在使用jenkins ...

  10. backslash and newline separated by space

    原来是因为\  后面多了一个空格 检查写的代码中将\后面的空格去掉就可以了.