2016黑龙江省赛problemB *随机数*已知三点求外接圆圆心模板

首先有一个随机数的概念:

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  (xx0)2+(yy0)2=r2 .

Input

First line contains  T(T20)  denoting the number of test cases.

   T  cases follows. For each cases: 

  First line contains an integer  n(3n30000) , indicates the number of the points.

  Followed by  n  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)

Output

For each case, if there exists a circle meet the condition, output "YOUGE", otherwise, output "NIUGE"

Sample Input

2
5
1.213551 0.151532
1.515114 1.451512
2.566665 1.531351
3.516151 5.561565
6.515162 8.515195
10
1.000000 0.000000
2.000000 0.000000
3.000000 0.000000
4.000000 0.000000
5.000000 0.000000
6.000000 0.000000
7.000000 0.000000
8.000000 0.000000
9.000000 0.000000
10.000000 0.000000

Sample Output

YOUGE
NIUGE

#include<cstdio>
#include<ctime>
#include<cmath>
#include<cstdlib>
    using namespace std;
double x[30005];
double y[30005];
#define eps 1e-2
double 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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值