HDU 6242
题意略。
思路:这个题的思路非常诡异。由于题目保证存在这样一个圆,那么每个点在这个圆上的概率是1/2,我任选3个点,这3个点都在这个圆上的概率是1 / 8。
不都在这个圆上的概率是7 / 8,在这样选取30次后,还没有找到这个圆的概率是0.018,根据这个条件我们可以暴力验证。
详见代码:
#include<bits/stdc++.h>
#define maxn 100005
#define eps 1e-6
using namespace std; struct Point{
double x,y;
Point(double a = ,double b = ){
x = a,y = b;
}
}; Point store[maxn];
int T,n; Point circumcenter(Point a,Point b,Point c){
double a1 = b.x - a.x,b1 = b.y - a.y,c1 = (a1 * a1 + b1 * b1) / ;
double a2 = c.x - a.x,b2 = c.y - a.y,c2 = (a2 * a2 + b2 * b2) / ;
double d = a1 * b2 - a2 * b1;
return Point(a.x + (c1 * b2 - c2 * b1) / d,a.y + (a1 * c2 - a2 * c1) / d);
}
double dist(Point p1,Point p2){
double dx = p1.x - p2.x,dy= p1.y - p2.y;
return sqrt(dx * dx + dy * dy);
}
int sgn(double x,double y){
if(fabs(x - y) < eps) return ;
else if(x + eps < y) return -;
else return ;
} int main(){
scanf("%d",&T);
srand(time());
while(T--){
scanf("%d",&n);
for(int i = ;i < n;++i){
scanf("%lf%lf",&store[i].x,&store[i].y);
}
Point center;
double R;
if(n == ){
center = Point(store[].x + ,store[].y);
R = ;
}
else if( < n && n <= ){
center = Point((store[].x + store[].x) / ,(store[].y + store[].y) / );
R = dist(center,store[]);
}
else{
int cnt = ;
while(cnt < (n + ) / ){
cnt = ;
int s1 = rand() % n,s2 = rand() % n,s3 = rand() % n;
while(s1 == s2 || s1 == s3 || s2 == s3){
if(s1 == s2) s1 = rand() % n;
if(s1 == s3) s3 = rand() % n;
if(s2 == s3) s2 = rand() % n;
}
center = circumcenter(store[s1],store[s2],store[s3]);
R = dist(center,store[s1]);
for(int i = ;i < n;++i){
double r = dist(store[i],center);
if(sgn(r,R) == ) ++cnt;
}
}
}
printf("%lf %lf %lf\n",center.x,center.y,R);
}
return ;
}
HDU 6242的更多相关文章
- HDU - 6242 Geometry Problem (几何,思维,随机)
Geometry Problem HDU - 6242 Alice is interesting in computation geometry problem recently. She found ...
- HDU 6242 Geometry Problem(计算几何 + 随机化)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6242 思路:当 n == 1 时 任取一点 p 作为圆心即可. n >= 2 && ...
- 2017 CCPC 哈尔滨站 HDU 6242
Geometry Problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Other ...
- HDU - 6242:Geometry Problem(随机+几何)
Alice is interesting in computation geometry problem recently. She found a interesting problem and s ...
- hdu 6242 Geometry Problem
Geometry Problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Other ...
- HDOJ 2111. Saving HDU 贪心 结构体排序
Saving HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- 【HDU 3037】Saving Beans Lucas定理模板
http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...
- hdu 4859 海岸线 Bestcoder Round 1
http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...
- HDU 4569 Special equations(取模)
Special equations Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
随机推荐
- 分享一个 Linux 环境下,强力的Python 小工具
场景 Linux 用户,经常需要在终端查看一些数据,从文件里看 或者网络协议获取数据并查看. 比如,查看文件里的json数据:比如,查看etcd里存下的数据. 如果直接看cat 或者 curl 得到的 ...
- git远程服务器回滚
1.git log查找commit hash 2.git reset --hard hash 回滚本地git库 3.git push -f origin(git仓库的url) branch名 强制提交
- 【MySQL】导出长数字到 Excel 避免转为科学计数法方法
MySQL 导出比较长的数字到 Excel 时,最后几位会变成 0,解决方法如下: 如果只需要导出展示.打印:可使用 CONCAT("\t",str) 如果需要后续处理,引用,最好 ...
- 利用dockerfile 安装一个nginx-1.14.1
FROM docker.io/centos MAINTAINER jim 107420988@qq.com ENV TZ "Asia/Shanghai" #ENV TERM xte ...
- ASP.NET Core MVC 之局部视图(Partial Views)
1.什么是局部视图 局部视图是在其他视图中呈现的视图.通过执行局部视图生成的HTML输出呈现在调用视图中.与视图一样,局部视图使用 .cshtml 文件扩展名.当希望在不同视图之间共享网页的可重用部分 ...
- SQLServer2000同步复制技术实现步骤
SQLServer2000同步复制技术实现步骤 一. 预备工作 1.发布服务器,订阅服务器都创建一个同名的windows用户,并设置相同的密码,做为发布快照文件夹的有效访问用户 --管理工具 --计算 ...
- Unity经典游戏编程之:球球大作战
版权声明: 本文原创发布于博客园"优梦创客"的博客空间(网址:http://www.cnblogs.com/raymondking123/)以及微信公众号"优梦创客&qu ...
- Linux(Ubuntu)安装Swift和Swiftlint
很多时候iOS开发完毕需要接入CI中,而很多CI是基于Linux的,需要在Linux平台安装Swift和Swiftlint,下面就是针对这两个软件的安装步骤. Swift安装 环境 系统:Ubuntu ...
- apicloud 开发环境搭建
之前做过appcan 手机应用的开发,工作需要切换的apicloud , 开发环境的的搭建是开发的第一步,let's go 1新建应用 step1 注册账号 注册apicloud 账号:https ...
- Go标准库--net/http学习
Go中对网络的支持提供了标准库,net包提供了可移植的网络I/O接口,包括TCP/IP.UDP.域名解析和Unix域socket. http包提供了HTTP客户端和服务端的实现. 一般我们用http肯 ...