POJ 1673 EXOCENTER OF A TRIANGLE

这道题就是求点的时候麻烦了点,思路还是很简单的

刚开始把向量反向写成了swap(x,y),其实应该是x=-x,y=-y

#include<stdio.h>
#include<math.h>
#include<algorithm>
using namespace std;
const double eps=1e-8;
struct Point {
    double x,y;
    Point(){}
    Point(double xx,double yy){x=xx;y=yy;}
    Point operator+(Point b){return Point(x+b.x,y+b.y);}
    double operator^(const Point b)const{
        return x*b.y-y*b.x;
    }
    Point operator-(Point b){return Point(x-b.x,y-b.y);}
};
struct Line {
    Point s,e;
    Line(){};
    Line(Point ss,Point ee){s=ss;e=ee;}
    Point operator &(Line b){
        Point res=s;
        double t=((s-b.e)^(b.s-b.e))/((s-e)^(b.s-b.e));
        res.x+=(e.x-s.x)*t;
        res.y+=(e.y-s.y)*t;
        return res;
    }
};
double xmul(Point p0,Point p1,Point p2){
    return (p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y);
}
double dist(Point a,Point b){
    return sqrt((b.x-a.x)*(b.x-a.x)+(b.y-a.y)*(b.y-a.y));
}
Point getPoint(Point a,Point b,Point c){
    Point q;
    q=Point(-(b.y-a.y),b.x-a.x);
    if(xmul(a,b,c)>eps) {
        q.x=-q.x;
        q.y=-q.y;
    }
    double d=dist(a,b);
    q.x*=d/sqrt(q.x*q.x+q.y*q.y);
    q.y*=d/sqrt(q.x*q.x+q.y*q.y);

    q.x=a.x+q.x;
    q.y=a.y+q.y;

    return q;
}

Point p[3];
int main(){
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
#endif // ONLINE_JUDGE
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%lf%lf%lf%lf%lf%lf",&p[0].x,&p[0].y,&p[1].x,&p[1].y,&p[2].x,&p[2].y);
        Point c,d,r,q;
        c=getPoint(p[0],p[1],p[2]);
        d=getPoint(p[0],p[2],p[1]);
        r=Point((c.x+d.x)/2,(c.y+d.y)/2);

        c=getPoint(p[1],p[2],p[0]);
        d=getPoint(p[1],p[0],p[2]);
        q=Point((c.x+d.x)/2,(c.y+d.y)/2);

        Point o;
        o=Line(p[0],r)&Line(p[1],q);
        printf("%.4f %.4f\n",o.x,o.y);
    }
    return 0;
}
时间: 2024-08-27 21:37:00

POJ 1673 EXOCENTER OF A TRIANGLE的相关文章

POJ 1673 三角形垂心

EXOCENTER OF A TRIANGLE Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 3209   Accepted: 1259 Description Given a triangle ABC, the Extriangles of ABC are constructed as follows: On each side of ABC, construct a square (ABDE, BCHJ and AC

POJ1673 EXOCENTER OF A TRIANGLE(三角形垂心)

题目链接: http://poj.org/problem?id=1673 题目描述: EXOCENTER OF A TRIANGLE Description Given a triangle ABC, the Extriangles of ABC are constructed as follows: On each side of ABC, construct a square (ABDE, BCHJ and ACFG in the figure below). Connect adjacen

POJ 1673

可以证明O是三角形ABC的垂心. 作图辅助线,一个很重要的技巧是延长中线等中线. 可以证明三角形DNA全等于ABC.然后通过角度变换容易证明AQ垂直于BC. #include <iostream> #include <cstdio> #include <algorithm> using namespace std; struct point{ double x,y; }A,B,C; const int inf=10000000; int main(){ int t; d

[转] POJ几何分类

转自:http://blog.csdn.net/tyger/article/details/4480029 计算几何题的特点与做题要领:1.大部分不会很难,少部分题目思路很巧妙2.做计算几何题目,模板很重要,模板必须高度可靠.3.要注意代码的组织,因为计算几何的题目很容易上两百行代码,里面大部分是模板.如果代码一片混乱,那么会严重影响做题正确率.4.注意精度控制.5.能用整数的地方尽量用整数,要想到扩大数据的方法(扩大一倍,或扩大sqrt2).因为整数不用考虑浮点误差,而且运算比浮点快. 一.点

【转】计算几何题目推荐

打算转下来好好做计算几何了. 原文地址:http://blog.sina.com.cn/s/blog_49c5866c0100f3om.html 其实也谈不上推荐,只是自己做过的题目而已,甚至有的题目尚未AC,让在挣扎中.之所以推荐计算几何题,是因为,本人感觉ACM各种算法中计算几何算是比较实际的算法,在很多领域有着重要的用途计算几何题的特点与做题要领:1.大部分不会很难,少部分题目思路很巧妙2.做计算几何题目,模板很重要,模板必须高度可靠.3.要注意代码的组织,因为计算几何的题目很容易上两百行

poj 2954 Triangle(Pick定理)

链接:http://poj.org/problem?id=2954 Triangle Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5043   Accepted: 2164 Description A lattice point is an ordered pair (x, y) where x and y are both integers. Given the coordinates of the vertices

hdu 3934&amp;&amp;poj 2079 (凸包+旋转卡壳+求最大三角形面积)

链接:http://poj.org/problem?id=2079 Triangle Time Limit: 3000MS   Memory Limit: 30000K Total Submissions: 8173   Accepted: 2423 Description Given n distinct points on a plane, your task is to find the triangle that have the maximum area, whose vertices

Soj题目分类

-----------------------------最优化问题------------------------------------- ----------------------常规动态规划  SOJ1162 I-Keyboard  SOJ1685 Chopsticks SOJ1679 Gangsters SOJ2096 Maximum Submatrix  SOJ2111 littleken bg SOJ2142 Cow Exhibition  SOJ2505 The County

优质题表(机密版)

转载请注明出处:http://www.cnblogs.com/dashuzhilin/p/4556803.html 思维题: poj 1528 poj 1597 poj 2538 poj 2608 poj 2612 poj 2361 poj 2339 poj 2664 uva 10894 uva 10921   uva 10922   uva 10929 uva 10931   uva 10800   uva 10878 uva 10976   uva 10323   uva 201 poj 2