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()
{
    //freopen("data.txt","r",stdin);
    double xax,xay;
    double xbx,xby;
    double xcx,xcy;
    double xfx,xfy;
    double xex,xey;
    double xdx,xdy;
    double xpx,xpy;
    double xqx,xqy;
    double xrx,xry;
    int t;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%lf %lf",&xax,&xay);
        scanf("%lf %lf",&xbx,&xby);
        scanf("%lf %lf",&xcx,&xcy);
        xfx = a*xbx+b*xax; xfy = a*xby+b*xay;
        xex = a*xax+b*xcx; xey = a*xay+b*xcy;
        xdx = a*xcx+b*xbx; xdy = a*xcy+b*xby;
        double linadk,linadb;
        int sumad=0;
        if(fabs(xax-xdx-0)<=eqs)
        {
            linadb = xax;
            sumad = 0;
        }else if(fabs(xay-xdy-0)<=eqs)
        {
            linadb = xay;
            sumad = 1;
        }else
        {
            sumad = 2;
            linadk = (xay-xdy)/(xax-xdx);
            linadb = xay - linadk * xax;
        }
        double linfck,linfcb;
        int sumfc=0;
        if(fabs(xfx-xcx-0)<=eqs)
        {
            linfcb = xfx;
            sumfc = 0;
        }else if(fabs(xfy-xcy-0)<=eqs)
        {
            linfcb = xay;
            sumfc = 1;
        }else
        {
            sumfc = 2;
            linfck = (xfy-xcy)/(xfx-xcx);
            linfcb = xfy - linfck * xfx;
        }
        double linbek,linbeb;
        int sumbe=0;
        if(fabs(xbx-xex-0)<=eqs)
        {
            linbeb = xbx;
            sumbe = 0;
        }else if(fabs(xby-xey-0)<=eqs)
        {
            linbeb = xby;
            sumbe = 1;
        }else
        {
            sumbe = 2;
            linbek = (xby-xey)/(xbx-xex);
            linbeb = xby - linbek * xbx;
        }
        if(sumfc==0)
        {
            xrx = linfcb;
            if(sumad==1)
            {
                xry = linadb;
            }else if(sumad==2)
            {
                xry = linadk*xrx+linadb;
            }
            xqx = linfcb;
            if(sumbe==1)
            {
                xqy = linbeb;
            }else if(sumbe==2)
            {
                xqy = linbek*xqx+linbeb;
            }
        }else if(sumfc==1)
        {
            xry = linfcb;
            if(sumad==0)
            {
                xrx = linadb;
            }else if(sumad==2)
            {
                xrx = (xry-linadb)/linadk;
            }
            xqy = linfcb;
            if(sumbe==0)
            {
                xqx = linbeb;
            }else if(sumbe==2)
            {
                xqx = (xqy-linbeb)/linbek;
            }
        }else
        {
            if(sumad==0)
            {
                xrx = linadb;
                xry = xrx*linfck+linfcb;
            }else if(sumad==1)
            {
                xry = linadb;
                xrx = (xry-linfcb)/linfck;
            }else if(sumad==2)
            {
                xrx = (linfcb-linadb)/(linadk-linfck);
                xry = linfck * xrx + linfcb;
            }
            if(sumbe==0)
            {
                xqx = linbeb;
                xqy = xqx*linfck+linfcb;
            }else if(sumbe==1)
            {
                xqy = linbeb;
                xqx = (xqy-linfcb)/linfck;
            }else if(sumad==2)
            {
                xqx = (linfcb-linbeb)/(linbek-linfck);
                xqy = linfck * xqx + linfcb;
            }
        }
        if(sumbe==0)
        {
            xpx = linbeb;
            if(sumad==1)
            {
                xpy = linadb;
            }else if(sumad==2)
            {
                xpy = linadk*xpx+linadb;
            }
        }else if(sumbe==1)
        {
            xpy = linbeb;
            if(sumad==0)
            {
                xpx = linadb;
            }else if(sumad==2)
            {
                xpx = (xpy-linadb)/linadk;
            }
        }else if(sumbe==2)
        {
            if(sumad==0)
            {
                xpx = linadb;
                xpy = xrx*linbek+linbeb;
            }else if(sumad==1)
            {
                xpy = linadb;
                xpx = (xry-linbeb)/linbek;
            }else if(sumad==2)
            {
                xpx = (linbeb-linadb)/(linadk-linbek);
                xpy = linbek * xpx + linbeb;
            }
        }
        double ans = 0;
        ans+=(xpx*xqy-xpy*xqx);
        ans+=(xqx*xry-xqy*xrx);
        ans+=(xrx*xpy-xry*xpx);
        if(ans<0)
        {
            ans = ans * -1;
        }
        ans = ans/2;
        printf("%.0lf\n",ans);
    }
    return 0;
}

版权声明:本文博客原创文章,博客,未经同意,不得转载。

时间: 2024-12-19 14:40:52

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(计算几何)

这题只要根据题目,利用向量把点一个个求出来计算面积即可 不过据说有一种证明方法可以证明面积是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

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 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

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