UVA 11178

来源:互联网 发布:华农c语言实验答案 编辑:程序博客网 时间:2024/06/05 22:52

传送门

紫书P260

//china no.1#pragma comment(linker, "/STACK:1024000000,1024000000")#include <vector>#include <iostream>#include <string>#include <map>#include <stack>#include <cstring>#include <queue>#include <list>#include <stdio.h>#include <set>#include <algorithm>#include <cstdlib>#include <cmath>#include <iomanip>#include <cctype>#include <sstream>#include <functional>#include <stdlib.h>#include <time.h>#include <bitset>using namespace std;#define pi acos(-1)#define endl '\n'#define srand() srand(time(0));#define me(x,y) memset(x,y,sizeof(x));#define foreach(it,a) for(__typeof((a).begin()) it=(a).begin();it!=(a).end();it++)#define close() ios::sync_with_stdio(0); cin.tie(0);#define FOR(x,n,i) for(int i=x;i<=n;i++)#define FOr(x,n,i) for(int i=x;i<n;i++)#define W while#define sgn(x) ((x) < 0 ? -1 : (x) > 0)#define bug printf("***********\n");typedef long long LL;const int INF=0x3f3f3f3f;const LL LINF=0x3f3f3f3f3f3f3f3fLL;const int dx[]={-1,0,1,0,1,-1,-1,1};const int dy[]={0,1,0,-1,-1,1,-1,1};const int maxn=1e3+10;const int maxx=3e5+100;const double EPS=1e-10;const int mod=10000007;#define mod(x) ((x)%MOD);template<class T>inline T min(T a,T b,T c) { return min(min(a,b),c);}template<class T>inline T max(T a,T b,T c) { return max(max(a,b),c);}template<class T>inline T min(T a,T b,T c,T d) { return min(min(a,b),min(c,d));}template<class T>inline T max(T a,T b,T c,T d) { return max(max(a,b),max(c,d));}inline LL Scan(){    int f=1;char C=getchar();LL x=0;    while (C<'0'||C>'9'){if (C=='-')f=-f;C=getchar();}    while (C>='0'&&C<='9'){x=x*10+C-'0';C=getchar();}    x*=f;return x;}//freopen( "in.txt" , "r" , stdin );//freopen( "data.out" , "w" , stdout );//cerr << "run time is " << clock() << endl;struct Point{    double x, y;    Point(double x = 0, double y = 0) : x(x), y(y) { }    inline void input()    {        scanf("%lf%lf",&x,&y);    }    inline void print()    {        printf("%.6lf %.6lf\n",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); }bool operator < (const Point& a, const Point b){    return a.x < b.x || (a.x == b.x && a.y < b.y);}int dcmp(double x){    if(fabs(x) < EPS) return 0;    else return x < 0 ? -1 : 1;}bool operator == (const Point& a, const Point& b){    return dcmp(a.x-b.x) == 0 && dcmp(a.y-b.y);}//向量点积double Dot(Vector A, Vector B) { return A.x*B.x + A.y*B.y; }//向量长度double Length(Vector A) { return sqrt(Dot(A, A)); }//向量夹角//求两向量的夹角,cos(a,b) =( 向量a * 向量b ) / (| a | * | b |) =  x1*x2 + y1*y2 / (| a | * | b |)double Angle(Vector A, Vector B) { return acos(Dot(A, B) / Length(A) / Length(B)); }//向量叉积  |a||b|sin<a,b>//叉积的结果也是一个向量,是垂直于向量a,b所形成的平面,如果看成三维坐标的话是在 z 轴上,上面结果是它的模。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); }//向量逆时针旋转rad度(弧度)Vector Rotate(Vector A, double rad){    return Vector(A.x*cos(rad)-A.y*sin(rad), A.x*sin(rad)+A.y*cos(rad));}//计算向量A的单位法向量。左转90°,把长度归一。调用前确保A不是零向量。Vector Normal(Vector A){    double L = Length(A);    return Vector(-A.y/L, A.x/L);}//共线或平行bool Converxline(Vector A,Vector B,Vector C,Vector D){    if((Area2(A,B,C)==0&&Area2(A,B,D)==0)    ||Area2(A,B,C)*Area2(A,B,D)>0||Area2(C,D,A)*Area2(C,D,B)>0)        return false;    else        return true;}/***************************************************************************** 用直线上的一点p0和方向向量v表示一条指向。直线上的所有点P满足P = P0+t*v;* 如果知道直线上的两个点则方向向量为B-A, 所以参数方程为A+(B-A)*t;* 当t 无限制时, 该参数方程表示直线。* 当t > 0时, 该参数方程表示射线。* 当 0 < t < 1时, 该参数方程表示线段。*****************************************************************************///直线交点,须确保两直线 P+tv 和 Q+tw 有唯一交点。当且仅当Cross(v,w)非0Point 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;}//点到直线距离double DistanceToLine(Point P, Point A, Point B){    Vector v1 = B - A, v2 = P - A;    return fabs(Cross(v1, v2) / Length(v1)); //不取绝对值,得到的是有向距离}//点到线段的距离double DistanceToSegmentS(Point P, Point A, Point B){    if(A == B) return Length(P-A);    Vector v1 = B-A, v2 = P-A, v3 = P-B;    if(dcmp(Dot(v1, v2)) < 0) return Length(v2);    else if(dcmp(Dot(v1, v3)) > 0) return Length(v3);    else return fabs(Cross(v1, v2)) / Length(v1);}//点在直线上的投影Point GetLineProjection(Point P, Point A, Point B){    Vector v = B - A;    return A+v*(Dot(v, P-A)/Dot(v, v));}//线段相交判定,交点不在一条线段的端点bool SegmentProperIntersection(Point a1, Point a2, Point b1, Point b2){    double c1 = Cross(a2-a1, b1-a1), c2 = Cross(a2-a1, b2-a1);    double c3 = Cross(b2-b1, a1-b1), c4 = Cross(b2-b1, a2-b1);    return dcmp(c1)*dcmp(c2) < 0 && dcmp(c3)*dcmp(c4) < 0;}//判断点是否在点段上,不包含端点bool OnSegment(Point P, Point a1, Point a2){    return dcmp(Cross(a1-P, a2-P) == 0 && dcmp((Dot(a1-P, a2-P)) < 0));}//计算凸多边形面积double ConvexPolygonArea(Point *p, int n){    double area = 0;    for(int i = 1; i < n-1; i++)        area += Cross(p[i] - p[0], p[i+1] - p[0]);    return area/2;}//计算多边形的有向面积double PolygonArea(Point *p, int n){    double area = 0;    for(int i = 1; i < n-1; i++)        area += Cross(p[i] - p[0], p[i+1] - p[0]);    return area/2;}/************************************************************************ Morley定理:三角形每个内角的三等分线,相交成的三角形是等边三角形。* 欧拉定理:设平面图的定点数,边数和面数分别为V,E,F。则V+F-E = 2;************************************************************************///Morley定理Point getD(Point A, Point B, Point C){    Vector v1=C-B;    double a1=Angle(A-B,v1);    v1=Rotate(v1,a1/3);    Vector v2=B-C;    double a2=Angle(A-C,v2);    v2=Rotate(v2,-a2/3);    return GetLineIntersection(B,v1,C,v2);}//欧拉定理/*void oula(int n){    n--;    int c=n,e=n;    for(int i=0;i<n;i++)        for(int j=i+1;j<n;j++)        {            if(SegmentProperIntersection(P[i],[i+1],P[j],P[j+1]))            {                V[c++]=GetLineIntersection(P[i],P[i+1]-P[i],P[j],P[j+1]-P[j]);            }        }    sort(V,V+c);    c=unique(V,V+c)-V;    for(int i=0;i<c;i++)        for(int j=0;j<n;j++)    {        if(OnSegment(V[i],P[j],p[j+1])) e++;    }    //cout<<e+2-c<<endl;}*///定义圆struct Circle{    Point c;    double r;    Circle(Point c,double r):c(c),r(r){}    Point point(double a)    {        return Point(c.x+cos(a)*r,c.y+sin(a)*r);    }    inline void input()    {        scanf("%lf%lf",&c.x,&c.y);    }    inline void print()    {        printf("%.6lf %.6lf\n",c.x,c.y);    }};int main(){    int T;    Point A, B, C, D, E, F;    scanf("%d",&T);    while(T--)    {        scanf("%lf%lf%lf%lf%lf%lf",&A.x, &A.y, &B.x, &B.y, &C.x, &C.y);        D = getD(A, B, C);        E = getD(B, C, A);        F = getD(C, A, B);        printf("%lf %lf %lf %lf %lf %lf\n", D.x, D.y, E.x, E.y, F.x, F.y);    }    return 0;}


原创粉丝点击