2016黑龙江省赛problemB *随机数*已知三点求外接圆圆心模板
来源:互联网 发布:兰州知豆电动车多少钱 编辑:程序博客网 时间:2024/04/29 13:08
首先有一个随机数的概念:
srand和rand()配合使用产生伪随机数序列。rand函数在产生随机数前,需要系统提供的生成伪随机数序列的种子,rand根据这个种子的值产生一系列随机数。如果系统提供的种子没有变化,每次调用rand函数生成的伪随机数序列都是一样的。srand(unsigned seed)通过参数seed改变系统提供的种子值,从而可以使得每次调用rand函数生成的伪随机数序列不同,从而实现真正意义上的“随机”。通常可以利用系统时间来改变系统的种子值,即srand(time(NULL)),可以为rand函数提供不同的种子值,进而产生不同的随机数序列。
也就是srand()函数是用于产生不同的随机数种子,rand()函数是用于产生对应于该随机数种的随机数序列!两者都在cstdlib头文件下面
time(NULL)
用于得到某个时该距离当前时刻的秒数
随机序列的产生有两种方法->这里就不展开啦QAQ
题意:有n个点,问是否存在n/3及以上个点在同一个圆上
解题思路:随机产生三个点,利用求外接圆圆心的模板求出这三个点产生的圆,然后枚举所有的点,如果在这个圆上,那么总数+1,如果总数大于等于n/3,则得到肯定答案。复杂度是O(N^4),
答案错误的概率:一个点有大于等于1/3的概率是位于答案圆上,假设为1/3,选择三个点,都在正确圆上的概率为1/27,即得到正确圆的概率为1/27;
则在得一个圆的时候,有26/27是得不到那个正确的圆,for循环开1000次,得不到圆的概率是(26/27)^1000,就接近于0啦~\(≧▽≦)/~
Problem B
Time Limit : 6000/3000ms (Java/Other) Memory Limit : 131072/131072K (Java/Other)
Total Submission(s) : 155 Accepted Submission(s) : 13
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
There are n points in a geometrical plane, ask if there is a circle that contains at least ⌊n/3⌋ points on it or not. The point is on the circle (center: (x0,y0) , radius: r) if (x−x0)2+(y−y0)2=r2 .
Input
First line contains T(T≤20) denoting the number of test cases.
T cases follows. For each cases:
First line contains an integern(3≤n≤30000) , indicates the number of the points.
Followed byn lines, each line contains two numbers Xi,Yi , indicates the location of the i-th point. Xi,Yi retain six decimal fractions.
(|Xi|,|Yi|≤10000000)
First line contains an integer
Followed by
Output
For each case, if there exists a circle meet the condition, output "YOUGE", otherwise, output "NIUGE"
Sample Input
251.213551 0.1515321.515114 1.4515122.566665 1.5313513.516151 5.5615656.515162 8.515195101.000000 0.0000002.000000 0.0000003.000000 0.0000004.000000 0.0000005.000000 0.0000006.000000 0.0000007.000000 0.0000008.000000 0.0000009.000000 0.00000010.000000 0.000000
Sample Output
YOUGENIUGE#include<cstdio>#include<ctime>#include<cmath>#include<cstdlib> using namespace std;double x[30005];double y[30005];#define eps 1e-2double sqr(double x){ return x*x;}void Cir(double ax,double ay,double bx,double by,double cx,double cy,double &x,double &y){ double a1=atan2(by-ay,bx-ax)+acos(-1.)/2; double a2=atan2(cy-by,cx-bx)+acos(-1.)/2; ax=(ax+bx)/2,ay=(ay+by)/2; bx=(cx+bx)/2,by=(cy+by)/2; double r=(sin(a2)*(ax-bx)+cos(a2)*(by-ay))/(sin(a1)*cos(a2)-sin(a2)*cos(a1)); x=ax+r*cos(a1),y=ay+r*sin(a1);}int main(){ int cas; int t; srand(time(0)); scanf("%d",&cas); while(cas--){ scanf("%d",&t); int limit=t/3;//地板函数或者取整函数,表示小于x的最大整数 for(int i=1;i<=t;i++){ scanf("%lf%lf",&x[i],&y[i]); } int p=0; for(int ii=800;ii;ii--){ int t1=rand()%t+1; int t2=rand()%t+1; while(t1==t2){ t2=rand()%t+1; } int t3=rand()%t+1; while(t1==t3||t2==t3){ t3=rand()%t+1; } double Xx,Yy,R; Cir(x[t1],y[t1],x[t2],y[t2],x[t3],y[t3],Xx,Yy); R=sqr(x[t3]-Xx)+sqr(y[t3]-Yy); int sum=0; for(int k=1;k<=t;k++){ if(fabs(sqr(x[k]-Xx)+sqr(y[k]-Yy)-R)<=eps) sum++; if(sum>=limit) break; } if(sum>=limit){ p=1; break; } //break; } if(p==1) printf("YOUGE\n"); else printf("NIUGE\n"); } return 0;}
1 0
- 2016黑龙江省赛problemB *随机数*已知三点求外接圆圆心模板
- 已知三点坐标,求外接圆圆心坐标与半径。
- c++ 三点求外接圆圆心 3维实现
- 已知三点求圆心与半径
- 三角形外接圆圆心
- 三角形外接圆圆心公式
- 三角形外接圆圆心坐标
- 三点求圆心模板
- 求三角形外接圆圆心坐标的算法
- 三角形外接圆圆心 算法 删改版
- 求三角形的外接圆圆心个半径
- 平面三角形外接圆圆心与半径求解算法
- hdoj4720Naive and Silly Muggles【求外接圆圆心】
- 2016年黑龙江省赛J题 S number【数位dp模板题】
- 已知圆上三点坐标求圆心
- problemB
- problemB
- S number(2016黑龙江省赛J题)
- VMware虚拟磁盘编程指导(二)
- VMware虚拟磁盘编程指导(三)
- [Cloud Computing]Mechanisms: Identity and Access Management
- 论域
- UVA 714 Copying Books
- 2016黑龙江省赛problemB *随机数*已知三点求外接圆圆心模板
- 键盘侦听事件
- [Cloud Computing]Mechanisms: Import and Export
- 欢迎使用CSDN-markdown编辑器
- Android 使用PLDroidPlayer播放网络视频 根据视频角度自动旋转
- nginx配置系统
- BLE蓝牙4.0经典问答【转】
- 文章标题
- IOS Dev Intro - Render YpCbCr