1659. Regular Triangles(计算几何)

题意:给定一个等边三角形,求三角形里面三个点和三角形外的三个点,使其中的点组成的等边三角形不少于9个。

思路:让里面的三角形中的一个点在中心,然后使外面的点与给定的点和中心点构成等边三角形,,三角形个数正好是9个。


#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <string>
#define LL long long
#define DB double

using namespace std;
struct cpoint{
    DB x,y;
    cpoint(){}
    cpoint(DB a,DB b){x=a,y=b;}
    void get(){scanf("%lf%lf",&x,&y);}
    void out(){printf("%.10lf %.10lf\n",x,y);}
};
struct cvector{
    DB x,y;
    cvector(){}
    cvector(DB a,DB b){x=a,y=b;}
};
cvector operator-(cpoint a,cpoint b)
{
    return  cvector(a.x-b.x,a.y-b.y);
}
cpoint operator+(cpoint a,cvector b)
{
    return cpoint(a.x+b.x,a.y+b.y);
}
cvector operator*(DB t,cvector a)
{
    return cvector(t*a.x,t*a.y);
}
cpoint a,b,c,o;
int main()
{
    #ifndef ONLINE_JUDGE
    freopen("in.txt","r",stdin);
    #endif
    a.get();b.get();c.get();
    o.x = (a.x+b.x+c.x)/3;
    o.y = (a.y+b.y+c.y)/3;
    cvector v1,v2,v3;
    v1 = a-o;v2 = b-o;v3=c-o;
    cpoint tmp;
    o.out();
    tmp = o+(-0.25)*(a-b);tmp.out();
    tmp = o+(-0.25)*(c-b);tmp.out();
    tmp = o+(-1.0)*v1;tmp.out();
    tmp = o+(-1.0)*v2;tmp.out();
    tmp = o+(-1.0)*v3;tmp.out();
    return 0;
}


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