ACM Greater New York 2017 H. Triangle to Hexagon

24 篇文章 0 订阅

题目:点击打开链接
题意:AA点的坐标为(0,0)(0,0),BB点的坐标是(0,a)(0,a),CC点坐标为(c,d)(c,d),三角形ABCABC的外接圆为OO,内心为点II,NN为BIBI的延长线与圆OO的交点,MM点和PP点同理,问EF、FG、GH、HJ、JK、KEEF、FG、GH、HJ、JK、KE的长度分别为多少。

分析:计算几何模板,照着题目给的条件模拟一遍就行。

代码:

#pragma comment(linker, "/STACK:102400000,102400000")///手动扩栈
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cassert>
#include<string>
#include<cstdio>
#include<bitset>
#include<vector>
#include<cmath>
#include<ctime>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<set>
#include<map>
using namespace std;
#define debug test
#define mst(ss,b) memset((ss),(b),sizeof(ss))
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define inf 0x3f3f3f3f
#define eps 1e-10
#define PI acos(-1.0)
typedef pair<int,int> PII;
const ll mod = 1e9+7;
const int N = 1e6+10;

ll gcd(ll p,ll q){return q==0?p:gcd(q,p%q);}
ll qp(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
int to[4][2]={{-1,0},{1,0},{0,-1},{0,1}};

int cmp(double a, double b) {
    if (fabs(a - b) < eps) return 0;
    return a < b ? -1 : 1;
}

struct Point { ///点
    double x, y;
    Point(double x = 0, double y = 0):x(x), y(y) {}
    bool operator != (const Point &tmp) const {
        return (cmp(x, tmp.x) != 0 || cmp(y, tmp.y) != 0);
    }
    double dist(const Point point) const {
        return sqrt((x - point.x) * (x - point.x) + (y - point.y) * (y - point.y));
    }
} a, b, c, e, f, g, h, i, j, k, m, n, p;

struct Line { ///线
    Point u, v;
    Line(Point a = 0, Point b = 0):u(a), v(b) {}
    Point intersection(const Line &line) const {
        Point ret = u;
        double tmp = ((u.x - line.u.x) * (line.u.y - line.v.y) - (u.y - line.u.y) * (line.u.x - line.v.x))
                     / ((u.x - v.x) * (line.u.y - line.v.y) - (u.y - v.y) * (line.u.x - line.v.x));
        ret.x += (v.x - u.x) * tmp;
        ret.y += (v.y - u.y) * tmp;
        return ret;
    }
};

struct Triangle { ///三角形
    Point a, b, c;
    Triangle(Point a = 0, Point b = 0, Point c = 0):a(a), b(b), c(c) {}
    Point outCenter() {///外心
        Line u, v;
        u.u.x = (a.x + b.x) / 2;
        u.u.y = (a.y + b.y) / 2;
        u.v.x = u.u.x - a.y + b.y;
        u.v.y = u.u.y + a.x - b.x;
        v.u.x = (a.x + c.x) / 2;
        v.u.y = (a.y + c.y) / 2;
        v.v.x = v.u.x - a.y + c.y;
        v.v.y = v.u.y + a.x - c.x;
        return u.intersection(v);
    }
    Point inCenter() {///内心
        Point ua, ub, va, vb;
        double m, n;
        ua = a;
        m = atan2(b.y - a.y, b.x - a.x);
        n = atan2(c.y - a.y, c.x - a.x);
        ub.x = ua.x + cos((m + n) / 2.0);
        ub.y = ua.y + sin((m + n) / 2.0);
        va = b;
        m = atan2(a.y - b.y, a.x - b.x);
        n = atan2(c.y - b.y, c.x - b.x);
        vb.x = va.x + cos((m + n) / 2.0);
        vb.y = va.y + sin((m + n) / 2.0);
        return Line(ua, ub).intersection({va, vb});
    }

};

struct Circle { ///圆
    Point center;
    double r;
    Circle(Point center = 0, double r = 0):center(center), r(r) {}
    std::pair<Point, Point> intersection(const Line &line) const {///圆与直线的交点
        Point p = center, p1, p2;
        double tmp;
        p.x += line.u.y - line.v.y;
        p.y += line.v.x - line.u.x;
        p = line.intersection({p, center});
        tmp = sqrt(r * r - p.dist(center) * p.dist(center)) / line.u.dist(line.v);
        p1.x = p.x + (line.v.x - line.u.x) * tmp;
        p1.y = p.y + (line.v.y - line.u.y) * tmp;
        p2.x = p.x - (line.v.x - line.u.x) * tmp;
        p2.y = p.y - (line.v.y - line.u.y) * tmp;
        return std::make_pair(p1, p2);
    };
} o;

void read() {
    b.y = a.x = a.y = 0.0;
    scanf("%*d%lf%lf%lf", &b.x, &c.x, &c.y);
}

Point myIntersection(Circle circle, Line line) {
    auto tmp = circle.intersection(line);
    return (tmp.first != line.u && tmp.first != line.v) ? tmp.first : tmp.second;
}

void init() {
    o.center = Triangle(a, b, c).outCenter();
    o.r = o.center.dist(a);
    i = Triangle(a, b, c).inCenter();

    n = myIntersection(o, Line(b, i));
    m = myIntersection(o, Line(a, i));
    p = myIntersection(o, Line(c, i));

    e = Line(a, b).intersection(Line(p, n));
    f = Line(a, c).intersection(Line(p, n));
    g = Line(m, n).intersection(Line(a, c));
    h = Line(m, n).intersection(Line(b, c));
    j = Line(p, m).intersection(Line(b, c));
    k = Line(a, b).intersection(Line(p, m));
}

void print(Point a, Point b) {
    printf(" %.4f", a.dist(b));
}

void out() {
    print(e, f);
    print(f, g);
    print(g, h);
    print(h, j);
    print(j, k);
    print(k, e);
    putchar('\n');
}

int main() {
    int t;
    scanf("%d", &t);
    for (int i = 1; i <= t; i++) printf("%d", i), read(), init(), out();
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值