题目链接

比赛时C++上__float128都被卡精度,然后扔给队友用Java的BigDecimal过了

算法不多说,求三角形外心可以参考 维基百科 https://zh.wikipedia.org/wiki/%E5%A4%96%E6%8E%A5%E5%9C%93

这里用到了分数类。根据算法中涉及到的各处细节可以发现,这道题可以满足条件:①只涉及到有理数运算;②有理数用分数表示时,分子分母均不超过1e(12*3)=1e36级别。故,我们可以把原先用浮点数来表示的数据,改成用分数类表示,具体实现可以见代码。

#include<bits/stdc++.h>
using namespace std;
typedef long long LL; struct frac
{
__int128 p,q;
frac(){}
frac(__int128 _p,__int128 _q)
{
if(_q<) _p=-_p,_q=-_q;
p=_p,q=_q;
}
frac operator +(const frac&rhs)
{
__int128 a,b;
b=q*rhs.q;
a=p*rhs.q+q*rhs.p;
if(b==) return frac(,);
__int128 g=__gcd(a,b);
a/=g;
b/=g;
return frac(a,b);
}
frac operator -(const frac&rhs)
{
__int128 a,b;
b=q*rhs.q;
a=p*rhs.q-q*rhs.p;
if(b==) return frac(,);
__int128 g=__gcd(a,b);
a/=g;
b/=g;
return frac(a,b);
}
frac operator *(const frac&rhs)
{
__int128 a,b;
b=q*rhs.q;
a=p*rhs.p;
if(b==) return frac(,);
__int128 g=__gcd(a,b);
a/=g;
b/=g;
return frac(a,b);
}
frac operator /(const frac&rhs)
{
__int128 a,b;
b=q*rhs.p;
a=p*rhs.q;
if(b==) return frac(,);
__int128 g=__gcd(a,b);
a/=g;
b/=g;
return frac(a,b);
}
bool operator <(const frac&rhs)const
{
return p*rhs.q<rhs.p*q;
}
bool operator >(const frac&rhs)const
{
return p*rhs.q>rhs.p*q;
}
bool operator ==(const frac&rhs)const
{
return !(p*rhs.q<rhs.p*q)&&!(p*rhs.q>rhs.p*q);
}
}; struct Point
{
frac x,y;
void read()
{
LL t1,t2;
cin>>t1>>t2;
x=frac((__int128)t1,),y=frac((__int128)t2,);
}
Point(){}
Point(frac _x,frac _y)
{
x=_x,y=_y;
}
Point operator -(const Point& rhs)
{
return Point(x-rhs.x,y-rhs.y);
}
};
typedef Point Vector; frac Dot(Vector A,Vector B)
{
return A.x*B.x+A.y*B.y;
} Point waixin(Point a,Point b,Point c) {
frac a1 = b.x - a.x, b1 = b.y - a.y, c1 = (a1*a1 + b1*b1)/frac(,);
frac a2 = c.x - a.x, b2 = c.y - a.y, c2 = (a2*a2 + b2*b2)/frac(,);
frac d = a1*b2 - a2*b1;
return Point(a.x + (c1*b2 - c2*b1)/d, a.y + (a1*c2 -a2*c1)/d);
}
Point p1,p2,p3,c,p; int main()
{
int T;
scanf("%d",&T);
while(T--)
{
p1.read();
p2.read();
p3.read();
c=waixin(p1,p2,p3);
p.read();
if(Dot(p-c,p-c)>Dot(p1-c,p1-c))
puts("Accepted");
else
puts("Rejected");
}
}

hdu 6206 : Apple 【计算几何 + 分数类】的更多相关文章

  1. HDU 6206 Apple【计算几何+高精度Java】

    Problem Description Apple is Taotao's favourite fruit. In his backyard, there are three apple trees ...

  2. HDU 6206 Apple ( 高精度 && 计算几何 && 三点构圆求圆心半径 )

    题意 : 给出四个点,问你第四个点是否在前三个点构成的圆内,若在圆外输出"Accepted",否则输出"Rejected",题目保证前三个点不在一条直线上. 分 ...

  3. HDU 6206 Apple (高精确度+JAVA BigDecimal)

    Problem Description Apple is Taotao's favourite fruit. In his backyard, there are three apple trees ...

  4. HDU 6206 Apple

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6206 判断给定一点是否在三角形外接圆内. 给定三角形三个顶点的坐标,如何求三角形的外心的坐标呢? 知乎 ...

  5. HDU 5387 Clock(分数类+模拟)

    题意: 给你一个格式为hh:mm:ss的时间,问:该时间时针与分针.时针与秒针.分针与秒针之间夹角的度数是多少. 若夹角度数不是整数,则输出最简分数形式A/B,即A与B互质. 解析: 先计算出总的秒数 ...

  6. 连分数(分数类模板) uva6875

    //连分数(分数类模板) uva6875 // 题意:告诉你连分数的定义.求连分数,并逆向表示出来 // 思路:直接上分数类模板.要注意ai可以小于0 #include <iostream> ...

  7. OC2_分数类

    // // Fraction.h // OC2_分数类 // // Created by zhangxueming on 15/6/10. // Copyright (c) 2015年 zhangxu ...

  8. 第十七周oj刷题——Problem B: 分数类的四则运算【C++】

    Description 编写分数类Fraction,实现两个分数的加.减.乘和除四则运算.主函数已给定. Input 每行四个数,分别表示两个分数的分子和分母,以0 0 0 0 表示结束. Outpu ...

  9. HDU 4998 Rotate (计算几何)

    HDU 4998 Rotate (计算几何) 题目链接http://acm.hdu.edu.cn/showproblem.php?pid=4998 Description Noting is more ...

随机推荐

  1. C# CLR20R3 程序终止的几种解决方案 【转】

    [转]CLR20R3 程序终止的几种解决方案   这是因为.NET Framework 1.0 和 1.1 这两个版本对许多未处理异常(例如,线程池线程中的未处理异常)提供支撑,而 Framework ...

  2. 中国MOOC_面向对象程序设计——Java语言_期末考试编程题_1细胞自动机

    期末考试编程题 返回   这是期末考试的编程题 温馨提示: 1.本次考试属于Online Judge题目,提交后由系统即时判分. 2.学生可以在考试截止时间之前提交答案,系统将取其中的最高分作为最终成 ...

  3. Canvas入门04-绘制矩形

    使用的API: ctx.strokeRect(x, y, width, height) 给一个矩形描边 ctx.fillRect(x, y, width, height) 填充一个矩形 ctx.cle ...

  4. Express中间件body-parser

    在http请求种,POST.PUT.PATCH三种请求方法中包含着请求体,也就是所谓的request,在Nodejs原生的http模块中,请求体是要基于流的方式来接受和解析. body-parser是 ...

  5. net 架构师-数据库-sql server-003-T-SQL 基本语句

    3.1 基本SELECT语句 SELECT [ALL|DISTINCT] [TOP (<expression>)  [PERCENT] [WITH TIES]] <coloumn  ...

  6. OpenGL字体绘制

    /* glfont.hpp sdragonx 2019-08-15 00:03:33 opengl字体类,提供初学者参考学习 opengl初始化之后,创建字体 font.init(L"微软雅 ...

  7. 有十个div,怎样实现选中其中一个,改变其背景色,另外九个不变,当选中另一个时又改变另一个的背景色

    这个是jq写的,可以自己下载一个js库,配上这个就可以了,里面的div可以用class控制,比如你10个div class为a1 也就是<div class="a1"> ...

  8. jQuery之样式的类操作

    方法:添加类addClass    .删除类removeClass. 切换类toggleClass <style> div { width: 150px; height: 150px; b ...

  9. Pure播放器

    我是的本地应用,并不会拿你的隐私数据.

  10. author认证模块

    author认证模块 用auth模块 你就用全套 不是自己写一部分 用别人一部分 ​ 创建超级管理员,用于登录DJango admin的后台管理 ​ 命令:createsuperuser,输入顺序用户 ...