UVALive - 8295 Triangle to Hexagon

题意:就是求里面的六边形的每条边的距离

思路:直接求就好了(把题目标号的顺序读反了,保佑队友不杀之恩)

代码:

#include <set>
#include <map>
#include <queue>
#include <stack>
#include <math.h>
#include <vector>
#include <string>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#define zero(a) fabs(a)<eps
#define max( x, y )  ( ((x) > (y)) ? (x) : (y) )
#define min( x, y )  ( ((x) < (y)) ? (x) : (y) )
#define lowbit(x) (x&(-x))
#define debug(a) cerr<<#a<<"=="<<a<<endl
typedef long long LL;
const long double pi=acos(-1.0);
const long double eps=1e-8;
const int inf=0x3f3f3f3f;
const LL linf=0x3f3f3f3f3f3f3f3f;
using namespace std;

#define zero(x) (((x)>0?(x):-(x))<eps)
int sgn(long double x)
{
    if(fabs(x) < eps)return 0;
    if(x < 0)return -1;
    else return 1;
}
struct point
{
    long double x,y;
    point (){}
    point (long double _x,long double _y)
    {
        x=_x,y=_y;
    }
};
struct Line
{
    point a,b;
    Line(){}
    Line(point _a,point _b)
    {
        a=_a;
        b=_b;
    }
};
struct circle {
    point o;
    long double r;
    void print() {
        printf(" center:(%.4Lf, %.4Lf) rad: %.4Lf\n", o.x, o.y, r);
    }
};
long double xmult(point p1,point p2,point p0)
{
    return (p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y);
}
point intersection(point u1,point u2,point v1,point v2)
{
    point ret=u1;
    long double t=((u1.x-v1.x)*(v1.y-v2.y)-(u1.y-v1.y)*(v1.x-v2.x))
             /((u1.x-u2.x)*(v1.y-v2.y)-(u1.y-u2.y)*(v1.x-v2.x));
    ret.x+=(u2.x-u1.x)*t;
    ret.y+=(u2.y-u1.y)*t;
    return ret;
}
point intersection(Line u,Line v)
{
    point ret=u.a;
    long double t=((u.a.x-v.a.x)*(v.a.y-v.b.y)-(u.a.y-v.a.y)*(v.a.x-v.b.x))
             /((u.a.x-u.b.x)*(v.a.y-v.b.y)-(u.a.y-u.b.y)*(v.a.x-v.b.x));
    ret.x+=(u.b.x-u.a.x)*t;
    ret.y+=(u.b.y-u.a.y)*t;
    return ret;
}
long double dist(point a,point b)
{
    return (long double)sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
point circumcenter(point a,point b,point c)
{
    Line u,v;
    u.a.x=(a.x+b.x)/2;
    u.a.y=(a.y+b.y)/2;
    u.b.x=u.a.x-a.y+b.y;
    u.b.y=u.a.y+a.x-b.x;
    v.a.x=(a.x+c.x)/2;
    v.a.y=(a.y+c.y)/2;
    v.b.x=v.a.x-a.y+c.y;
    v.b.y=v.a.y+a.x-c.x;
    return intersection(u,v);
}
point incenter(point a,point b,point c)
{
    Line u,v;
    long double m,n;
    u.a=a;
    m=atan2(b.y-a.y,b.x-a.x);
    n=atan2(c.y-a.y,c.x-a.x);
    u.b.x=u.a.x+cos((m+n)/2);
    u.b.y=u.a.y+sin((m+n)/2);
    v.a=b;
    m=atan2(a.y-b.y,a.x-b.x);
    n=atan2(c.y-b.y,c.x-b.x);
    v.b.x=v.a.x+cos((m+n)/2);
    v.b.y=v.a.y+sin((m+n)/2);
    return intersection(u,v);
}
circle getNqc(point a, point b, point c) {
    long double C = dist(a, b);
    long double B = dist(a, c);
    long double A = dist(b, c);
    circle cir;
    cir.o.x = (A*a.x + B*b.x + C*c.x) / (A + B + C);
    cir.o.y = (A*a.y + B*b.y + C*c.y) / (A + B + C);
    cir.r = sqrt((A + B - C)*(A - B + C)*(-A + B + C) / (A + B + C)) / 2;
    return cir;
}
void intersection_line_circle(point c,long double r,point l1,point l2,point& p1,point& p2)
{
    point p=c;
    long double t;
    p.x+=l1.y-l2.y;
    p.y+=l2.x-l1.x;
    p=intersection(p,c,l1,l2);
    t=sqrt(r*r-dist(p,c)*dist(p,c))/dist(l1,l2);
    p1.x=p.x+(l2.x-l1.x)*t;
    p1.y=p.y+(l2.y-l1.y)*t;
    p2.x=p.x-(l2.x-l1.x)*t;
    p2.y=p.y-(l2.y-l1.y)*t;
}
Line line[10];

int main()
{
    int T;
    scanf("%d",&T);
    while(T--){
        int p;
        long double t1,t2,t3;
        point A,B,C,I,P,N,M;
        cin>>p>>t1>>t2>>t3;
        A=point(0.0,0.0),B=point(t1,0),C=point(t2,t3);
        circle qwe=getNqc(A,B,C);
        I=qwe.o;
        point wo=circumcenter(A,B,C);

        long double wr=dist(A,wo);
        point a1,a2;
        intersection_line_circle(wo,wr,I,A,a1,a2);
        if(fabs(a1.x-A.x)<eps&&fabs(a1.y-A.y)<eps){
            M=a2;
        }
        else{
            M=a1;
        }
        intersection_line_circle(wo,wr,I,B,a1,a2);
        if(fabs(a1.x-B.x)<eps&&fabs(a1.y-B.y)<eps){
            N=a2;
        }
        else{
            N=a1;
        }
        intersection_line_circle(wo,wr,I,C,a1,a2);
        if(fabs(a1.x-C.x)<eps&&fabs(a1.y-C.y)<eps){
            P=a2;
        }
        else{
            P=a1;
        }
        point E,F,K,J,H,G;
        G=intersection(Line(A,C),Line(M,N));
        H=intersection(Line(M,N),Line(C,B));
        J=intersection(Line(C,B),Line(M,P));
        K=intersection(Line(M,P),Line(A,B));
        E=intersection(Line(A,B),Line(N,P));
        F=intersection(Line(N,P),Line(A,C));
        printf("%d %.4Lf %.4Lf %.4Lf %.4Lf %.4Lf %.4Lf\n",p,dist(E,F),dist(F,G),dist(G,H),dist(H,J),dist(J,K),dist(K,E));
    }
    return 0;
}
/*

3
1 3 2.5 3

1
1 2 1 1.732
*/

原文地址:https://www.cnblogs.com/lalalatianlalu/p/8984755.html

时间: 2024-08-13 22:28:51

UVALive - 8295 Triangle to Hexagon的相关文章

LA UVaLive 7371 Triangle (水题,判矩形)

题意:给定两个三角形,问你能不能拼成矩形. 析:很明显,要想是矩形,必须是四个角是直角,那么三角形必须是直角三角形,然后就是只能斜边相对,然后呢?就没了. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <string> #include <functional> #include <cstdlib> #inc

Python 学习之二:Python超短教程

前言 本教程综合Stanford CS231N和UC Berkerley CS188的Python教程. 教程很短,但适合有一定编程基础,学过其他语言的童鞋. Python 启动Python 解释器 Python可以有两种使用方式,一种就是使用解释器interpreter,类似Matlab,输入一行代码,运行一行:另一种就是编写一个py后缀的文档,称为脚本,然后python xxx.py运行脚本script.这里我们使用解释器. 在已安装Python的情况下,在Terminal输入python,

Python basics

The tutorial is from Dan Klein and Pieter Abbeel A good tutorial: https://docs.python.org/2/tutorial/ Table of Contents Invoking the Interpreter Operators Strings Dir and Help Built-in Data Structures Lists Tuples Sets Dictionaries Writing Scripts In

UVALive 6176 Faulhaber&#39;s Triangle

题目链接 http://acm.sdibt.edu.cn/vjudge/ojFiles/uvalive/pdf/61/6177.pdf 题意是  给定一个数n,代表着一共有n个人,且他们的身高从1到n. 要求让这n个人站成一行,使得身高的排列呈波浪形,比如低高低或者高低高. 注意:n = 1 ,  ans = 1;    n = 2 ,  ans = 2; 动态规划. 解题思路: 每次新加入的点k,可以看成将之前的序列分成前后两部分,并且因为 k是最大的,所以要求k前面数的趋势应该是高低,k后面

(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

codeforces 560 C Gerald&#39;s Hexagon

神精度--------这都能过,随便算就好了,根本不用担心 就是把六边形补全成三角形,然后去掉补的三个三角形,然后面积除以边长1的三角形的面积即可.... #include<map> #include<string> #include<cstring> #include<cstdio> #include<cstdlib> #include<cmath> #include<queue> #include<vector&

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