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) {
        this->x = x;
        this->y = y;
    }
    void read() {
        scanf("%lf%lf", &x, &y);
    }
};

typedef Point Vector;

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);
}

double Cross(Vector A, Vector B) {return A.x * B.y - A.y * B.x;} //叉积
double Area2(Point A, Point B, Point C) {return Cross(B - A, C - A);} //有向面积

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() {
    scanf("%d", &t);
    while (t--) {
        Point A, B, C;
        A.read(); B.read(); C.read();
        Point D, E, F;
        D = (C - B) / 3 + B;
        E = (A - C) / 3 + C;
        F = (B - A) / 3 + A;
        Point R = GetLineIntersection(C, F - C, A, D - A);
        Point P = GetLineIntersection(B, E - B, A, D - A);
        Point Q = GetLineIntersection(C, F - C, B, E - B);
        printf("%d\n", (int)(fabs(Area2(P, Q, R)) / 2 + 0.5));
    }
    return 0;
}
时间: 2024-10-10 02:51:37

UVA 11437 - Triangle Fun(计算几何)的相关文章

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

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 =

【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 11178-Morley&#39;s Theorem(计算几何_莫雷定理)

Problem D Morley's Theorem Input: Standard Input Output: Standard Output Morley's theorem states that that the lines trisecting the angles of an arbitrary plane triangle meet at the vertices of an equilateral triangle. For example in the figure below

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 - 11401 - Triangle Counting (递推!)

UVA - 11401 Triangle Counting Time Limit: 1000MS Memory Limit: Unknown 64bit IO Format: %lld & %llu Submit Status Description Problem G Triangle Counting Input: Standard Input Output: Standard Output You are given n rods of length 1, 2-, n. You have

uva 194 - Triangle(几何)

题目链接:uva 194 - Triangle 注意两边一角,并接角的对边确定时(即用正弦定理求解时,可能会有多解的情况) #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> using namespace std; const double pi = 4 * atan(1); const double eps = 1e-4; double A[6]; void

uva 11401 - Triangle Counting(数论)

题目链接:uva 11401 - Triangle Counting 题目大意:有多少种方法可以从1,2,3...n中选出3个不同的数组成三角形,给出n,求种数. 解题思路:加法原理,设最大边为x的三角形有c(x)个,那么另外两条边长分别为y和z,根据三角形的形式可以的y+z>x,所以z的范围即为x?y<z<x 根据这个不等式可以得到每个y值所对应的z值个数,为等差数列,所以 c(x)=(x?1)?(x?2)2??x?12?2 然后根据递推:f(n)=∑i=1nc(i) 代码 #incl