Triangle Fun UVA - 11437

Triangle Fun

UVA - 11437

题意:给三角形,求一些三等分点,线段交点,求面积。

简单题~

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 const int inf = 0x3f3f3f3f;
 4 const double eps = 1e-12;
 5 const double pi = acos(-1.0);
 6
 7 struct Point {
 8     double x,y;
 9     Point (double x = 0, double y = 0) : x(x), y(y) {}
10 };
11 typedef Point Vector;
12 Vector operator + (Vector a, Vector b) {
13     return Vector (a.x + b.x, a.y + b.y);
14 }
15 Vector operator * (Vector a, double s) {
16     return Vector (a.x * s, a.y * s);
17 }
18 Vector operator / (Vector a, double p) {
19     return Vector (a.x / p, a.y / p);
20 }
21 Vector operator - (Point a, Point b) {
22     return Vector (a.x - b.x, a.y - b.y);
23 }
24 bool operator < (Point a, Point b) {
25     return a.x < b.x || (a.x == b.x && a.y < b.y);
26 }
27 int dcmp (double x) {
28     if(fabs(x) < eps) return 0;
29     return x < 0 ? -1 : 1;
30 }
31 bool operator == (const Point &a, const Point &b) {
32     return dcmp(a.x - b.x) == 0 && dcmp(a.y - b.y) == 0;
33 }
34 double Angel (Vector a) {
35     return atan2(a.y, a.x);
36 }
37 double Dot(Vector a, Vector b) {
38     return a.x * b.x + a.y * b.y;
39 }
40 double Length (Vector a) {
41     return sqrt(Dot(a, a));
42 }
43 double Angle (Vector a, Vector b) {
44     return acos(Dot(a, b) / Length(a) / Length(b));
45 }
46 double Cross (Vector a, Vector b) {
47     return a.x * b.y - a.y * b.x;
48 }
49 //两直线交点
50 Point GetLineIntersection (Point p, Vector v, Point q, Vector w) {
51     Vector u = p - q;
52     double t1 = Cross(w, u) / Cross(v, w);
53     double t2 = Cross(v, u) / Cross(v, w);
54     return p + v * t1;  //  return q + w * t2;
55 }
56 //多边形面积
57 double ConvexPolygonArea(Point *p, int n) {
58     double area = 0;
59     for(int i = 1; i < n-1; i++) {
60         area += Cross(p[i] - p[0], p[i+1] - p[0]);
61     }
62     return area / 2;
63 }
64
65 Point p[3],ch[3];
66 int main(){
67     int t;
68     //freopen("in.txt", "r", stdin);
69     scanf("%d", &t);
70     while(t--){
71         for(int i = 0; i < 3; i++){
72             scanf("%lf %lf", &p[i].x, &p[i].y);
73         }
74         Point d = p[1] + (p[2] - p[1])/3;
75         Point e = p[2] + (p[0] - p[2])/3;
76         Point f = p[0] + (p[1] - p[0])/3;
77         ch[0] = GetLineIntersection(p[0], d-p[0], p[1], e-p[1]);
78         ch[1] = GetLineIntersection(p[2], f-p[2], p[1], e-p[1]);
79         ch[2] = GetLineIntersection(p[2], f-p[2], p[0], d-p[0]);
80         double area = ConvexPolygonArea(ch,3);
81         printf("%.0lf\n", area);  //这里是四舍五入,如果强制转换是截断,会WA
82     }
83 }

时间: 2024-10-10 14:05:33

Triangle Fun UVA - 11437的相关文章

UVA - 11437 - Triangle Fun (计算几何~)

UVA - 11437 Triangle Fun Time Limit: 1000MS Memory Limit: Unknown 64bit IO Format: %lld & %llu Submit Status Description Problem A Triangle Fun Input: Standard Input Output: Standard Output In the picture below you can see a triangle ABC. Point D, E

UVa 11437 - Triangle Fun

了解矢量为交点的坐标. #include <iostream> #include <cstring> #include <cstdio> #include <algorithm> #include <cstdlib> #include <cmath> #define eqs 1e-8 using namespace std; double a = 2.0/3; double b = 1.0/3; int main() { //freo

UVa 11437 (梅涅劳斯定理) Triangle Fun

题意: 给出三角形ABC顶点的坐标,DEF分别是三边的三等分点.求交点所形成的三角形PQR的面积. 分析: 根据梅涅劳斯定理,我们得到: ,解得 另外还有:,解得 所以AR : RP : PD = 3 : 3 : 1 同理,BE和CF也被分成这样比例的三段. △ADC = (2/3)△ABC △CDR = (4/7)△ADC △CPR = (3/4)△CDR △PQR = (1/2)△CPR 所以:△PQR = (1/7)△ABC 1 #include <cstdio> 2 #include

UVA 11437 - Triangle Fun(计算几何)

这题只要根据题目,利用向量把点一个个求出来计算面积即可 不过据说有一种证明方法可以证明面积是1/7的原三角形 代码: #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> using namespace std; int t; struct Point { double x, y; Point() {} Point(double x, double y) { th

uva 11437

题意:给出一个三角形的三点,然后取三边的三等分点和相对的顶点连线,问围起来的三角形的面积. 题解:把CF.AD.BE三个向量先求出来,然后两两取交点,最后用叉积求面积,最后要四舍五入. #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> using namespace std; const double PI = acos(-1); const double e

几何基础专题

UVA 11437 Triangle Fun UVA 11800 Determine the Shape 四边形判定 UVA 11646 Athletics Track UVA 11817 Tunnelling the Earth 球面距离 UVA 1473 Dome of Circus UVA 11524 InCircle UVA 11731 Ex-circles 旁切圆 UVA 12300 Smallest Regular Polygon UVA 10566 Crossed Ladders

【UVA】11437 Triangle Fun(简单几何)

先求出在A,B,C上的三等分点在,这里使用向量运算进行加减就行了. 之后通过求出的三等分点 和 顶点的连线,求出3个交点. 最后用求出的三个交点算出面积. 注意:由于可能是钝角三角形,需要求其绝对值. 14116428 11437 Triangle Fun Accepted C++ 0.015 2014-08-30 03:27:36 #include <iostream> #include <cstdlib> #include <cstdio> #include <

UVA 11401 - Triangle Counting(数论+计数问题)

题目链接:11401 - Triangle Counting 题意:有1,2,3....n的边,求最多能组成的三角形个数. 思路:利用三角形不等式,设最大边为x,那么y + z > x 得 x - y < z < x 然后y取取值,可以从1取到x - 1,y为n时候,有n - 1个解,那么总和为0 + 1 + 2 +...+ (x - 2) = (x - 1) * ( x- 2) / 2; 然后扣除掉重复的y = z的情况,在y > x / 2时,每个y取值会出现一次y = z.

UVa 485 - Pascal&#39;s Triangle of Death

題目:打印Pascal三角到第一个到达10^60的行. 分析:字符串.大整數.模擬.f(i,j)= f(i-1,j-1)+ f(i-1,j) {組合數公式}. 說明:注意不小于10^60的數字有61位(⊙_⊙). #include <iostream> #include <cstdlib> #include <cstdio> using namespace std; int P[220][220][70] = {0}; int main() { for (int i =