Regular Triangles(计算几何)

http://acm.timus.ru/problem.aspx?space=1&num=1659


题意:给你一个正三角形的三个点坐标,求出在这个三角形内外分别3个点,使得以这些点为顶点的正三角形至少有9个


构造如下,各种卡精度伤不起啊!







code:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <math.h>
using namespace std;

int main()
{
    //freopen("input.txt","r",stdin);
    double x[5],y[5],ox[5],oy[5],ix[5],iy[5];
    while(scanf("%lf%lf",&x[0],&y[0])!=EOF)
    {
        for(int i=1;i<3;i++)
            scanf("%lf%lf",&x[i],&y[i]);
        ix[0] = (x[0] + x[1] + x[2]) /3.0;
        iy[0] = (y[0] + y[1] + y[2]) /3.0;
        for(int i=0;i<3;i++)
        {
            ox[i] = 2*ix[0] - x[i];
            oy[i] = 2*iy[0] - y[i];
        }

        //double l = sqrt( (x[0]-x[1])*(x[0]-x[1]) + (y[0]-y[1])*(y[0]-y[1]) );
        double l =1;
        ix[1] = ix[0] - l/2;ix[2] = ix[0] + l/2;
        iy[1] = iy[2] = iy[0] - l*sqrt(3.0)/2;

        for(int i=0;i<3;i++)
            printf("%.12f %.12f\n",ix[i],iy[i]);
        for(int i=0;i<3;i++)
            printf("%.12f %.12f\n",ox[i],oy[i]);
    }

    return 0;
}


你可能感兴趣的:(Regular Triangles(计算几何))