【HDU】6242-Geometry Problem
今天忽然心血来潮打开牛客网尝试了一下一站到底
前四道题都是不到二十分钟切完,然后第五道来了道计算几何
我也不会啊,于是就觉得大力随机也许可行
然鹅被精度卡到崩溃
后来我才知道
保证有解,是保证你的精度误差设置到\(10^{-3}\),有解,\(10^{-5}\)没有解
【脏话】
这题直接随机三个点求外接圆就好了,看看这个圆上有几个点,期望随机十次左右吧
注意把题里说不合法的也就是绝对值大于1e9的这样的圆都给扔掉就好了
(这也许不是篇题解,只是一篇吐槽)
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 100005
#define ba 47
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
res = 0;T f = 1;char c = getchar();
while(c < '0' || c > '9') {
if(c == '-') f = -1;
c = getchar();
}
while(c >= '0' && c <= '9') {
res = res * 10 +c - '0';
c = getchar();
}
res *= f;
}
template<class T>
void out(T x) {
if(x < 0) {x = -x;putchar('-');}
if(x >= 10) {
out(x / 10);
}
putchar('0' + x % 10);
}
mt19937 rnd(20020328);
int N;
bool vis[MAXN];
int rec[10];
struct Point {
db x,y;
Point(db _x = 0.0,db _y = 0.0) {
x = _x;y = _y;
}
friend Point operator + (const Point &a,const Point &b) {
return Point(a.x + b.x,a.y + b.y);
}
friend Point operator - (const Point &a,const Point &b) {
return Point(a.x - b.x,a.y - b.y);
}
friend db operator * (const Point &a,const Point &b) {
return a.x * b.y - a.y * b.x;
}
friend db dot(const Point &a,const Point &b) {
return a.x * b.x + a.y * b.y;
}
friend Point operator * (const Point &a,db d) {
return Point(a.x * d,a.y * d);
}
db norm() {
return sqrt(x * x + y * y);
}
}P[MAXN];
Point a[10];
struct Line {
Point a,b;
Line(Point _a = Point(),Point _b = Point()) {
a = _a;b = _b;
}
friend Point GetInsect(const Line &s,const Line &t) {
db S1 = (t.a - t.b) * (s.a - t.b);
db S2 = (t.b - t.a) * (s.b - t.a);
return s.a + (s.b - s.a) * (S1 / (S1 + S2));
}
};
bool dcmp(db a,db b) {
return fabs(a - b) < 1e-3;
}
bool calc() {
Point c;db r;
if(dcmp((a[2] - a[0]) * (a[1] - a[0]),0)) return false;
Point l1,l2;
l1.x = -(a[1] - a[0]).y;l1.y = (a[1] - a[0]).x;
l2.x = -(a[2] - a[0]).y;l2.y = (a[2] - a[0]).x;
Line s,t;
s.a = (a[0] + a[1]) * 0.5;s.b = s.a + l1;
t.a = (a[0] + a[2]) * 0.5;t.b = t.a + l2;
c = GetInsect(s,t);
r = (a[0] - c).norm();
if(fabs(c.x) > 1e9 || fabs(c.y) > 1e9 || r > 1e9) return false;
int cnt = 0;
for(int i = 1 ; i <= N ; ++i) {
if(dcmp((P[i] - c).norm(),r)) ++cnt;
}
if(cnt >= (N - 1) / 2 + 1) {
printf("%.6lf %.6lf %.6lf\n",c.x,c.y,r);
return true;
}
return false;
}
void Solve() {
read(N);
for(int i = 1 ; i <= N ; ++i) {
scanf("%lf%lf",&P[i].x,&P[i].y);
}
if(N == 1) {
Point c(0,0);db r = (P[1] - c).norm();
printf("%.6lf %.6lf %.6lf\n",c.x,c.y,r);
return;
}
else if(N <= 4) {
Point c = (P[1] + P[2]) * 0.5;
db r = (P[1] - c).norm();
printf("%.6lf %.6lf %.6lf\n",c.x,c.y,r);
return;
}
memset(vis,0,sizeof(vis));
while(1) {
for(int i = 0 ; i < 3 ; ++i) {
int t = (rnd() % N + N) % N + 1;
while(vis[t]) {
t = (rnd() % N + N) % N + 1;
}
a[i] = P[t];rec[i] = t;
vis[t] = 1;
}
if(calc()) return;
for(int i = 0 ; i < 3 ; ++i) vis[rec[i]] = 0;
}
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
srand(time(0));
int T;
read(T);
while(T--) Solve();
return 0;
}
【HDU】6242-Geometry Problem的更多相关文章
- 【BZOJ1700】[Usaco2007 Jan]Problem Solving 解题 动态规划
[BZOJ1700][Usaco2007 Jan]Problem Solving 解题 Description 过去的日子里,农夫John的牛没有任何题目. 可是现在他们有题目,有很多的题目. 精确地 ...
- 【HDU】4888 Redraw Beautiful Drawings 网络流【推断解是否唯一】
传送门:pid=4888">[HDU]4888 Redraw Beautiful Drawings 题目分析: 比赛的时候看出是个网络流,可是没有敲出来.各种反面样例推倒自己(究其原因 ...
- 洛谷P1919 【模板】A*B Problem升级版 题解(FFT的第一次实战)
洛谷P1919 [模板]A*B Problem升级版(FFT快速傅里叶) 刚学了FFT,我们来刷一道模板题. 题目描述 给定两个长度为 n 的两个十进制数,求它们的乘积. n<=100000 如 ...
- 【BZOJ1000】A+B Problem ★BZOJ1000题达成★
[BZOJ1000]A+B Problem Description 输入两个数字,输出它们之和 Input 一行两个数字A,B(0<=A,B<100) Output 输出这两个数字之和 S ...
- 【题解】CF45G Prime Problem
[题解]CF45G Prime Problem 哥德巴赫板子题? \(\frac{n(n+1)}{2}\)若是质数,则不需要分了. 上式 若是奇数,那么拆成2和另一个数. 上式 若是偶数吗,直接\(O ...
- 【BZOJ3218】a + b Problem 可持久化线段树优化建图
[BZOJ3218]a + b Problem 题解:思路很简单,直接最小割.S->i,容量为Bi:i->T,容量为Wi:所有符合条件的j->new,容量inf:new->i, ...
- 【题解】P4137 Rmq Problem(莫队)
[题解]P4137 Rmq Problem(莫队) 其实这道题根本就不用离散化! 因为显然有\(mex\)值是\(\le 2\times 10^5\)的,所以对于大于\(2\times 10^5\)的 ...
- HDU - 6242 Geometry Problem (几何,思维,随机)
Geometry Problem HDU - 6242 Alice is interesting in computation geometry problem recently. She found ...
- hdu 6242 Geometry Problem
Geometry Problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Other ...
随机推荐
- SVN的工作机制
一.C/S结构 二.基本操作 1. 检出(Checkout) 把服务器端版本库内容完整下载到本地. 2. 更新(Update) 把服务器端相对于本地的新的修改下载到本地. 3. 提交(Comm ...
- C++重写(覆盖)、重载、重定义、多态
1 重写(覆盖)override override是重写(覆盖)了一个方法,以实现不同的功能.一般用于子类在继承父类时,重写(覆盖)父类中的方法.函数特征相同,但是具体实现不同. 重写需要注意: 被重 ...
- ? 这是个很好的问题。Go 当前的 GC 显然做了一些额外的工作,但它也跟其他的工作并行执行,所以在具有备用 CPU 的系统上,Go 正在作出合理的选择。请看 https://golang.org/issue/17969 结束语(Closing notes) 通过研究 Go 垃圾收集器,我能够理解 Go GC 当前结构的背景以及它如何克服它的弱点。Go发展得非常快。如果你对 Go感兴趣,最好继
? 这是个很好的问题.Go 当前的 GC 显然做了一些额外的工作,但它也跟其他的工作并行执行,所以在具有备用 CPU 的系统上,Go 正在作出合理的选择.请看 https://golang.org/i ...
- kafka和rabbitmq对比
1.吞吐量kafka吞吐量更高:1)Zero Copy机制,内核copy数据直接copy到网络设备,不必经过内核到用户再到内核的copy,减小了copy次数和上下文切换次数,大大提高了效率.2)磁盘顺 ...
- C之函数返回一个以上的值
#include<stdio.h> #include<stdlib.h> //函数的返回值不能是数组 void add(int* a,int* b){ *a += 10; *b ...
- 使用badusb“烧鹅”制作“百度U盘”
HID攻击:USB HID攻击技术是一种利用USB接口伪造用户击键行为实施是攻击的方式.通过恶意USB HID设备连接主机后发送伪造的按键命令,篡改系统设置.运行恶意功能.这种技术区别于传统的USB攻 ...
- Spring事务管理2----编程式事务管理
编程式事务管理 通过使用将Spring框架提供的TransactionTemplate模板注入到业务层来进行事务管理,这样对业务层原来的代码修改过多.不利于项目的后期维护. 以下是声明式事务管理的具体 ...
- 字典和Model的互转
LHModel的简单使用: LHModel是一个JSON转model,model转JSON的工具类. 使用很多runtime的API.调用简单,真正能用到的只有两个方法. Model* model = ...
- 一个可以让vsftpd启动系统用户登陆ftp的例子
编辑 /etc/vsftpd.conf 如下: listen=YES anonymous_enable=NO local_enable=YES check_shell=NO write_enable= ...
- Ubuntu+Django+uWSGI+Nginx部署Django项目
安装uWSGI,pip依据自己要使用的python版本自行选择,python2.x版本使用pip进行安装,python3.x版本使用pip3进行安装 pip install uwsgi 配置uWSGI ...