hdu 6206 : Apple 【计算几何 + 分数类】
比赛时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 【计算几何 + 分数类】的更多相关文章
- HDU 6206 Apple【计算几何+高精度Java】
Problem Description Apple is Taotao's favourite fruit. In his backyard, there are three apple trees ...
- HDU 6206 Apple ( 高精度 && 计算几何 && 三点构圆求圆心半径 )
题意 : 给出四个点,问你第四个点是否在前三个点构成的圆内,若在圆外输出"Accepted",否则输出"Rejected",题目保证前三个点不在一条直线上. 分 ...
- HDU 6206 Apple (高精确度+JAVA BigDecimal)
Problem Description Apple is Taotao's favourite fruit. In his backyard, there are three apple trees ...
- HDU 6206 Apple
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6206 判断给定一点是否在三角形外接圆内. 给定三角形三个顶点的坐标,如何求三角形的外心的坐标呢? 知乎 ...
- HDU 5387 Clock(分数类+模拟)
题意: 给你一个格式为hh:mm:ss的时间,问:该时间时针与分针.时针与秒针.分针与秒针之间夹角的度数是多少. 若夹角度数不是整数,则输出最简分数形式A/B,即A与B互质. 解析: 先计算出总的秒数 ...
- 连分数(分数类模板) uva6875
//连分数(分数类模板) uva6875 // 题意:告诉你连分数的定义.求连分数,并逆向表示出来 // 思路:直接上分数类模板.要注意ai可以小于0 #include <iostream> ...
- OC2_分数类
// // Fraction.h // OC2_分数类 // // Created by zhangxueming on 15/6/10. // Copyright (c) 2015年 zhangxu ...
- 第十七周oj刷题——Problem B: 分数类的四则运算【C++】
Description 编写分数类Fraction,实现两个分数的加.减.乘和除四则运算.主函数已给定. Input 每行四个数,分别表示两个分数的分子和分母,以0 0 0 0 表示结束. Outpu ...
- HDU 4998 Rotate (计算几何)
HDU 4998 Rotate (计算几何) 题目链接http://acm.hdu.edu.cn/showproblem.php?pid=4998 Description Noting is more ...
随机推荐
- 理解ES6中的Iterator
一.为什么使用Iterator 我们知道,在ES6中新增了很多的特性,包括Map,Set等新的数据结构,算上数组和对象已经有四种数据集合了,就像数组可以使用forEach,对象可以使用for...in ...
- 推荐Calendar操作日期
package com.example.demo.Calender; import java.text.SimpleDateFormat;import java.util.Calendar;impor ...
- 【C语言--数据结构】线性表链式存储结构
直接贴代码 头文件 #ifndef __LINKLIST_H__ #define __LINKLIST_H__ typedef void LinkList; typedef struct _tag_L ...
- Oracle 高版本往低版本备份恢复的方法
1. 高版本的数据库备份恢复到低版本的数据库 有时候回报错, 提示version版本不一致, 2. 其实方法是expdp 导出的时候 增加一个参数就可以了 参数 一般的类型是 version=11.2 ...
- go io库
1 io.Reader和io.Writer的获取 tcp协议下的io.Reader是从conn中获取到的,因为要先建立conn,conn建立成功之后,然后读写数据. 2 真正的读写 2.1 io.Co ...
- 短信群发(Thinkphp内核)
public function save(){ $id = I('id'); $Goods = M('message'); $info = $Goods->find($id); //就收数据 $ ...
- Delphi中各个包中包含的控件
经常有朋友提这样的问题,“我原来在delphi5或者delphi6中用的很熟的控件到哪里去了?是不是在delphi7中没有了呢?这是不是意味着我以前写的代码全都不能够移植到delphi7中来了呢?是不 ...
- POJ 3259 Wormholes SPFA算法题解
版权声明:本文作者靖心,靖空间地址:http://blog.csdn.net/kenden23/,未经本作者同意不得转载. https://blog.csdn.net/kenden23/article ...
- 批处理遍历文件夹执行git pull
echo off & color 0A for /d %%f in (D:\www\*) do ( D: cd %%f chdir git pull ) pause 遍历D:\www\这个文件 ...
- mongodb启动报错,child process failed, exited with error number 1
error: child process failed, exited with error number 1 第一次安装mongodb,随后启动一般不会出现上面的错误,出现这种错误的原因一般是mon ...