Hdu-6242 2017CCPC-哈尔滨站 M.Geometry Problem 计算几何 随机
题面
题意:给你n个点,让你找到一个圆,输出圆心,和半径,使得有超过一半的点刚好在圆上.n<=1e5,题目保证了有解
题解:刚开始看着很不可做的样子,但是多想想,三点确定一个圆,三点啊!
现在有1/2的点都在圆上,意味着很多选出来的3个点都会导致同样的结果啊
我们同时可以说,每次随机一个点,这个点在圆上的概率为1/2,那任意三个点同时在圆上的概率就是1/8
所以我们随机来个几万次就好了啊!
注意的就是点数<=4的时候,1的时候输出自己就可以了,2,3,4的时候随便输出2个点的中点就行了
1 #include<bits/stdc++.h> 2 using namespace std; 3 struct point 4 { 5 double x,y; 6 }a[100005],pp; 7 int T,n,x,y,z; 8 #define eps 1e-10 9 double R; 10 point cit(point a,point b,point c) 11 { 12 point cp; 13 double a1=b.x-a.x,b1=b.y-a.y,c1=(a1*a1+b1*b1)/2; 14 double a2=c.x-a.x,b2=c.y-a.y,c2=(a2*a2+b2*b2)/2; 15 double d=a1*b2-a2*b1; 16 cp.x=a.x+(c1*b2-c2*b1)/d; 17 cp.y=a.y+(a1*c2-a2*c1)/d; 18 return cp; 19 } 20 double dis(point a,point b) 21 { 22 return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)); 23 } 24 int ok(point p) 25 { 26 int tot=0; 27 for (int i=1;i<=n;i++) 28 { 29 if (fabs(dis(p,a[i])-R)<eps) tot++; 30 if (tot>=(n+1)/2) return 1; 31 } 32 return 0; 33 } 34 int kk(point x,point y,point z) 35 { 36 if ((x.x-y.x)*(x.y-z.y)==(x.y-y.y)*(x.x-z.x)) return 1; 37 return 0; 38 } 39 int main() 40 { 41 srand(time(0)); 42 scanf("%d",&T); 43 while (T--) 44 { 45 scanf("%d",&n); 46 for (int i=1;i<=n;i++) scanf("%lf%lf",&a[i].x,&a[i].y); 47 if (n==1) 48 { 49 printf("%lf %lf 0\n",a[1].x,a[1].y); 50 continue; 51 } 52 if (n<=4) 53 { 54 pp.x=(a[1].x+a[2].x)/2; 55 pp.y=(a[1].y+a[2].y)/2; 56 printf("%lf %lf %lf\n",pp.x,pp.y,dis(pp,a[1])); 57 continue; 58 } 59 for (int i=1;i<=5000000;i++) 60 { 61 x=rand()*rand()%n+1; 62 y=rand()*rand()%n+1; 63 z=rand()*rand()%n+1; 64 if (x==y || y==z || x==z) continue; 65 if (kk(a[x],a[y],a[z])) continue; 66 pp=cit(a[x],a[y],a[z]); 67 R=dis(pp,a[x]); 68 if (ok(pp)) 69 { 70 printf("%lf %lf %lf\n",pp.x,pp.y,R); 71 break; 72 } 73 } 74 } 75 }
转载于:https://www.cnblogs.com/qywhy/p/9748389.html
Hdu-6242 2017CCPC-哈尔滨站 M.Geometry Problem 计算几何 随机相关推荐
- 2017CCPC哈尔滨 M:Geometry Problem(随机)
题目链接:http://acm.hdu.edu.cn/contests/contest_showproblem.php?pid=1013&cid=784 题意: 给你n个点,找出一个圆满足至少 ...
- HDU 1086 You can Solve a Geometry Problem too
You can Solve a Geometry Problem too Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/3276 ...
- HDU 1086 You can Solve a Geometry Problem too (判断线段交叉,线段跨立)
You can Solve a Geometry Problem too Time Limit:1000MS Memory Limit:32768KB 64bit IO Forma ...
- hdu 1086 A - You can Solve a Geometry Problem too (线段的规范相交非规范相交)
A - You can Solve a Geometry Problem too Time Limit:1000MS Memory Limit:32768KB 64bit IO For ...
- 2017CCPC哈尔滨 H:A Simple Stone Game
题目链接:http://acm.hdu.edu.cn/contests/contest_showproblem.php?pid=1008&cid=784 题意: 给你n个正整数,每次可以将某个 ...
- 2017CCPC哈尔滨 F:Permutation(构造)
题目链接:http://acm.hdu.edu.cn/contests/contest_showproblem.php?pid=1006&cid=784 题意: 让你构造一个1到n的全排列,满 ...
- 2017CCPC哈尔滨 D:X-Men
题目链接:http://acm.hdu.edu.cn/contests/contest_showproblem.php?pid=1004&cid=784 题意: 给一棵树,某些点上有人,每个时 ...
- 2017CCPC哈尔滨 B:K-th Number(二分)
题目链接:http://acm.hdu.edu.cn/contests/contest_showproblem.php?pid=1002&cid=784 题意: 给你n个数,之后求出所有连续区 ...
- 2017CCPC哈尔滨 A:Palindrome(manacher+树状数组)
题目链接:http://acm.hdu.edu.cn/contests/contest_showproblem.php?pid=1001&cid=784 题意: 给你一个串s,求出满足S[i] ...
最新文章
- C#版本的CPU性能测试
- 八大排序算法合集 (归并排序、交换排序、插入排序、选择排序......)
- 三点弯曲弹性模量怎么计算公式_拉力试验机常用力学计算公式
- oracle sql developer 查看游标结果集(3.0.04
- python24.dll_2_48_python24.dll
- 2.12 矩阵及乘法重要总结
- Solaris、Mac OS系统日志分析工具
- ubuntu6.06容易死机的一种解决方法
- hdoj1789:Doing Homework again (贪心)
- python zip用法_Python zip()用法及代码示例
- 超有意思的代码注释_程序员搞笑的代码注释:谁的代码注释我都不服,就服你的...
- Python进行websocket接口测试
- ClassFinal 加密 Java class文件工具
- 破解“还原卡”技术方法
- 联想台式计算机驱动程序,联想台式机网卡驱动,详细教您联想台式机网卡驱动...
- 基于java飞机大战游戏
- 用HBuilderX代替微信开发者工具
- java程序员 thinkpad_JAVA程序员笔记本电脑推荐?
- 竞价域名是什么意思?
- win8卸载java环境_Win8.1系统如何解压/卸载install.wim文件