uva 11437
2015-08-01 09:38
453 查看
题意:给出一个三角形的三点,然后取三边的三等分点和相对的顶点连线,问围起来的三角形的面积。
题解:把CF、AD、BE三个向量先求出来,然后两两取交点,最后用叉积求面积,最后要四舍五入。
题解:把CF、AD、BE三个向量先求出来,然后两两取交点,最后用叉积求面积,最后要四舍五入。
#include <cstdio> #include <cstring> #include <cmath> #include <algorithm> using namespace std; const double PI = acos(-1); const double eps = 1e-9; struct Point { double x, y; Point(double x = 0, double y = 0): x(x), y(y) {} }; typedef Point Vector; double Sqr(double x) { return x * x; } double dcmp(double x) { if (fabs(x) < eps) return 0; return x < 0 ? -1 : 1; } Vector operator + (const Point& A, const Point& B) { return Vector(A.x + B.x, A.y + B.y); } Vector operator - (const Point& A, const Point& B) { return Vector(A.x - B.x, A.y - B.y); } Vector operator * (const Point& A, double a) { return Vector(A.x * a, A.y * a); } Vector operator / (const Point& A, double a) { return Vector(A.x / a, A.y / a); } double Cross(const Vector& A, const Vector& B) { return A.x * B.y - A.y * B.x; } double Dot(const Vector& A, const Vector& B) { return A.x * B.x + A.y * B.y; } double Length(const Vector& A) { return sqrt(Dot(A, A)); } 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 A.x == B.x && A.y == B.y; } //得到两直线交点 Point GetLineIntersection(Point P, Vector v, Point Q, Vector w) { Point u = P - Q; double t = Cross(w, u) / Cross(v, w); return P + v * t; } Point A, B, C, D, E, F; int main() { int t; scanf("%d", &t); while (t--) { scanf("%lf%lf%lf%lf%lf%lf", &A.x, &A.y, &B.x, &B.y, &C.x, &C.y); Vector CF = Vector((B - C) + (A - B) * 2.0 / 3); Vector BE = Vector((A - B) + (C - A) * 2.0 / 3); Vector AD = Vector((C - A) + (B - C) * 2.0 / 3); Point P = GetLineIntersection(B, BE, A, AD); Point R = GetLineIntersection(C, CF, A, AD); Point Q = GetLineIntersection(B, BE, C, CF); double res = fabs(Cross(Q - P, R - P)); printf("%lld\n", (long long)(res / 2.0 + 0.5)); } return 0; }
相关文章推荐
- RedHat6.1配置在线yum资源
- Objective-C中的instancetype和id区别
- Shiro学习(11)缓存机制
- Shiro学习(10)Session管理
- 第一个只出现一次的字符,josephus环,最大子数组和
- App开发。
- 抽象类与接口、内部类 8.1
- JavaScript 对象
- js中动态添加长字符串,并保持换行
- 设计模式 业务封装 & 紧耦合 vs. 松耦合 & 简单工厂模式
- Shiro学习(9)JSP标签
- iOS的SQLite的使用
- 【SpringMVC整合MyBatis】springmvc和struts2的区别
- PAT (Advanced Level) 1097. Deduplication on a Linked List (25) 链表去重
- python调用Java-JPype使用介绍
- Hdu 5323 2015多校对抗赛三
- POJ2255 Tree Recovery 二叉树遍历
- Shiro学习(8)拦截器机制
- 百度地图之添加控件——比例尺、缩略图、平移缩放
- Zigbee系列 学习笔记二(工程文件分析)