uva 11437

题意:给出一个三角形的三点,然后取三边的三等分点和相对的顶点连线,问围起来的三角形的面积。

题解:把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;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-09-29 04:03:49

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

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

了解矢量为交点的坐标. #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 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 562 Dividing coins --01背包的变形

01背包的变形. 先算出硬币面值的总和,然后此题变成求背包容量为V=sum/2时,能装的最多的硬币,然后将剩余的面值和它相减取一个绝对值就是最小的差值. 代码: #include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> using namespace std; #define N 50007 int c[102],d

UVA 10341 Solve It

Problem F Solve It Input: standard input Output: standard output Time Limit: 1 second Memory Limit: 32 MB Solve the equation: p*e-x + q*sin(x) + r*cos(x) + s*tan(x) + t*x2 + u = 0 where 0 <= x <= 1. Input Input consists of multiple test cases and te