题目链接

比赛时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. OpenStack 实现技术分解 (7) 通用库 — oslo_config

    目录 目录 前文列表 扩展阅读 osloconfig argparse cfgpy class Opt class ConfigOpts CONF 对象的单例模式 前文列表 OpenStack 实现技 ...

  2. Spring中通过变量和import标签来控制加载哪些bean

    需求:根据设置变量,来加载某个spring的bean的配置文件,这个配置文件中,有某些使用的bean.在一些情况下,不希望这些bean被初始化和加载进context中,也不需要被外面访问到. 在spr ...

  3. shell基础命令

    什么是脚本? 脚本简单地说就是一条条的文字命令(一些指令的堆积),这些文字命令是可以看到的(如可以用记事本打开查看.编辑). 常见的脚本: JavaScript(JS,前端),VBScript, AS ...

  4. numpy 介绍和基础使用详解

    NUMPY INTRODUCTION NUMPY 提供了一个在Python中做科学计算的基础库,重在数值计算,主要用于处理多维数组,用于储存和处理大型矩阵,本身是由C语言开发,比python自身的列表 ...

  5. 【MM系列】SAP MB5B中FI凭证摘要是激活的/结果可能不正确 的错误

    公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[MM系列]SAP MB5B中FI凭证摘要是激活 ...

  6. Excel区域复制粘贴

    这段工作做的是利用JAVA实现Excel的一块区域的复制并粘贴. 就本身对于 Excel跟 鼠标来说,这也是一个非常简单的操作. 但是 用 java的poi来做,还是 有点儿吃力的. 下面是之前做的一 ...

  7. nginx+memcached缓存图片

    1.nginx的配置如下: location ^~ /images/ {     set $memcached_key  "$uri"; #用URI作为key去memcached中 ...

  8. tensorflow学习之tf.placeholder

    placeholder函数相当于一个占位符,tf.placeholder(dtype, shape=None, name=None) dtype:数据类型.常用的是tf.float32,tf.floa ...

  9. python每日一练:0005题

    第 0005 题: 你有一个目录,装了很多照片,把它们的尺寸变成都不大于 iPhone5 分辨率的大小. import cv2 import os def resize(path,sizeX,size ...

  10. ipad已停用 连接itunes怎么办

    问题描述: ipad 开机密码多次输入出错后,提示 ipad已停用 连接itunes 解决方法: 参考: https://jingyan.baidu.com/article/fb48e8bee9ef4 ...