poj1673EXOCENTER OF A TRIANGLE

链接

据说这题是垂心。。数学太弱没有看出来,写了分朴实无华的代码。。

旋转三边得到图中的外顶点,然后连接三角形顶点求交点,交上WA。。觉得没什么错误就去看了下discuss,发现都在说精度问题,果断开始水,最后+了epsAC了。。

  1 #include <iostream>
  2 #include<cstdio>
  3 #include<cstring>
  4 #include<algorithm>
  5 #include<stdlib.h>
  6 #include<vector>
  7 #include<cmath>
  8 #include<queue>
  9 #include<set>
 10 using namespace std;
 11 #define N 100000
 12 #define LL long long
 13 #define INF 0xfffffff
 14 const double eps = 1e-8;
 15 const double pi = acos(-1.0);
 16 const double inf = ~0u>>2;
 17 struct Point
 18 {
 19     double x,y;
 20      Point(double x=0,double y=0):x(x),y(y) {}
 21 }p[5];
 22 typedef Point pointt;
 23 pointt operator + (Point a,Point b)
 24 {
 25     return Point(a.x+b.x,a.y+b.y);
 26 }
 27 pointt operator - (Point a,Point b)
 28 {
 29     return Point(a.x-b.x,a.y-b.y);
 30 }
 31 int dcmp(double x)
 32 {
 33     if(fabs(x)<eps) return 0;
 34     else return x<0?-1:1;
 35 }
 36 Point rotate(Point a,double rad)
 37 {
 38     return Point(a.x*cos(rad)-a.y*sin(rad),a.x*sin(rad)+a.y*cos(rad));
 39 }
 40 bool intersection1(Point p1, Point p2, Point p3, Point p4, Point& p)      // 直线相交
 41 {
 42     double a1, b1, c1, a2, b2, c2, d;
 43     a1 = p1.y - p2.y;
 44     b1 = p2.x - p1.x;
 45     c1 = p1.x*p2.y - p2.x*p1.y;
 46     a2 = p3.y - p4.y;
 47     b2 = p4.x - p3.x;
 48     c2 = p3.x*p4.y - p4.x*p3.y;
 49     d = a1*b2 - a2*b1;
 50     if (!dcmp(d))    return false;
 51     p.x = (-c1*b2 + c2*b1) / d;
 52     p.y = (-a1*c2 + a2*c1) / d;
 53     return true;
 54 }
 55 double cross(Point a,Point b)
 56 {
 57     return a.x*b.y-a.y*b.x;
 58 }
 59 double mul(Point p0,Point p1,Point p2)
 60 {
 61     return cross(p1-p0,p2-p0);
 62 }
 63 int main()
 64 {
 65     int n,i;
 66     cin>>n;
 67     while(n--)
 68     {
 69         for(i = 1; i <= 3 ; i++)
 70         scanf("%lf%lf",&p[i].x,&p[i].y);
 71         Point p1,p2,p3,p4;
 72         if(dcmp(mul(p[1],p[2],p[3]))>0)
 73         {
 74             p1 = rotate(p[3]-p[1],3*pi/2.0);
 75             p2 = rotate(p[2]-p[1],pi/2.0);
 76         }
 77         else
 78         {
 79             p1 = rotate(p[3]-p[1],pi/2.0);
 80             p2 = rotate(p[2]-p[1],3*pi/2.0);
 81         }
 82         p1.x+=p[1].x;
 83         p1.y+=p[1].y;
 84         p2.x+=p[1].x;
 85         p2.y+=p[1].y;
 86         p1.x = (p1.x+p2.x)/2;
 87         p1.y = (p1.y+p2.y)/2;
 88
 89         if(dcmp(mul(p[2],p[1],p[3]))>0)
 90         {
 91             p3 = rotate(p[3]-p[2],3*pi/2.0);
 92             p4 = rotate(p[1]-p[2],pi/2.0);
 93         }
 94         else
 95         {
 96             p3 = rotate(p[3]-p[2],pi/2.0);
 97             p4 = rotate(p[1]-p[2],3*pi/2.0);
 98         }
 99         p3.x+=p[2].x;
100         p3.y+=p[2].y;
101         p4.x+=p[2].x;
102         p4.y+=p[2].y;
103         p3.x = (p3.x+p4.x)/2;
104         p3.y = (p3.y+p4.y)/2;
105         Point pp ;
106         intersection1(p1,p[1],p3,p[2],pp);
107         printf("%.4f %.4f\n",pp.x+eps,pp.y+eps);
108
109     }
110     return 0;
111 }

poj1673EXOCENTER OF A TRIANGLE

时间: 2024-08-24 15:30:38

poj1673EXOCENTER OF A TRIANGLE的相关文章

(leetcode题解)Pascal&#39;s Triangle

Pascal's Triangle  Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5,Return [ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1] ] 题意实现一个杨辉三角. 这道题只要注意了边界条件应该很好实现出来,C++实现如下 vector<vector<int>> generate(int

Lab 1: Write a java program for the triangle problem and test the program with Junit.

Tasks: 1. Install Junit(4.12), Hamcrest(1.3) with Eclipse 将两个jar包添加到工程中 2. Install Eclemma with Eclipse 3. Write a java program for the triangle problem and test the program with Junit. [Description of triangle problem]Function triangle takes three i

Solution to Triangle by Codility

question: https://codility.com/programmers/lessons/4 we need two parts to prove our solution. on one hand, there is no false triangular. Given the array has been sorted, if A[i]+A[i+1]>A[i+2], we can prove the existence of the triangle. for array A i

LeetCode (13) Pascal&#39;s Triangle (杨辉三角 )

题目描述 Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5, Return 从第三行开始,每行除了最左边和最右边两个数为1,其他数字都是上一行中相邻两个数字之和.根据上述规则可以写出下面的代码: class Solution { public: vector<vector<int> > generateRow1() { vector<in

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

POJ 1163 The Triangle

题目链接:http://poj.org/problem?id=1163 The Triangle Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 39022   Accepted: 23430 Description 7 3 8 8 1 0 2 7 4 4 4 5 2 6 5 (Figure 1) Figure 1 shows a number triangle. Write a program that calculat

LeetCode--Pascal&#39;s Triangle

Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5, Return [ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1] ] class Solution { public: vector<vector<int> > generate(int numRows) { vector<vector<in

? (triangle)

2.1 题目描述 给定一个无自环重边的无向图,求这个图的三元环1的个数以及补图2的三元环个数. 2.2 输入格式 第一行 2 个数 n, m ,分别表示图的点数.边数. 接下来 m 行,每行两个数 u, v ,表示一条连接 u, v 的无向边. 2.3 输出格式 一行两个数,依次表示原图的三元环个数以及补图的三元环的个数. 2.4 样例输入 5 5 1 2 1 3 2 3 2 4 3 4 2.5样例输出 2 1 2.6数据范围 对于 30% 的数据:n ≤ 100 对于 60% 的数据:m ≤

POJ 2079 Triangle [旋转卡壳]

Triangle Time Limit: 3000MS   Memory Limit: 30000K Total Submissions: 9525   Accepted: 2845 Description Given n distinct points on a plane, your task is to find the triangle that have the maximum area, whose vertices are from the given points. Input