题目大意:给定一种估算Pi的方法:给出一系列随机数,从中任选两个数,这两个数的最大公约数不大于1(互质)的概率为6/(Pi*Pi),然后给出一系列数,据此估算Pi的值。直接模拟就好了。

 #include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std; int gcd(int a, int b)
{
return b == ? a : gcd(b, a%b);
} int main()
{
#ifdef LOCAL
freopen("in", "r", stdin);
#endif
int n;
int a[];
while (scanf("%d", &n) && n)
{
for (int i = ; i < n; i++)
scanf("%d", &a[i]);
int cnt = ;
for (int i = ; i < n-; i++)
for (int j = i+; j < n; j++)
{
int lmax = max(a[i], a[j]);
int lmin = min(a[i], a[j]);
if (gcd(lmax, lmin) == )
cnt++;
}
if (cnt == )
{
printf("No estimate for this data set.\n");
continue;
}
int total = n*(n-)/;
printf("%.6lf\n", sqrt(6.0*total/cnt));
}
return ;
}

UVa 412 - Pi的更多相关文章

  1. uva 1354 Mobile Computing ——yhx

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABGcAAANuCAYAAAC7f2QuAAAgAElEQVR4nOy9XUhjWbo3vu72RRgkF5

  2. UVA&&POJ离散概率与数学期望入门练习[4]

    POJ3869 Headshot 题意:给出左轮手枪的子弹序列,打了一枪没子弹,要使下一枪也没子弹概率最大应该rotate还是shoot 条件概率,|00|/(|00|+|01|)和|0|/n谁大的问 ...

  3. BZOJ 1260&UVa 4394 区间DP

    题意: 给一段字符串成段染色,问染成目标串最少次数. SOL: 区间DP... DP[i][j]表示从i染到j最小代价 转移:dp[i][j]=min(dp[i][j],dp[i+1][k]+dp[k ...

  4. RASPBERRY PI wifi配置

    Raspberry Pi 手把手教你在树莓派上安装USB无线网卡支持WIFI 树莓派虽然已经有了有线网卡,但是并未配置无线网卡,移动性不够强,好在机器配备了2个USB口,当然要分一个出来给WIFI无线 ...

  5. UVA 572 油田连通块-并查集解决

    题意:8个方向如果能够连成一块就算是一个连通块,求一共有几个连通块. 分析:网上的题解一般都是dfs,但是今天发现并查集也可以解决,为了方便我自己理解大神的模板,便尝试解这道题目,没想到过了... # ...

  6. UVa 11300 Spreading the Wealth(有钱同使)

    p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: "Times New ...

  7. UVa 10387- Billiard

    UVa 10387- Billiard Table of Contents 1 题目 2 思路 3 代码 4 参考 1 题目 ============= Problem A: Billiard In ...

  8. 概率论 --- Uva 11181 Probability|Given

    Uva 11181 Probability|Given Problem's Link:   http://acm.hust.edu.cn/vjudge/problem/viewProblem.acti ...

  9. .Uva&LA部分题目代码

    1.LA 5694 Adding New Machine 关键词:数据结构,线段树,扫描线(FIFO) #include <algorithm> #include <cstdio&g ...

随机推荐

  1. angular实现select的ng-options

    html <div ng-controller="ngSelect"> <select ng-model="vm.selectVal" ng- ...

  2. jq之简单的表单验证

    <body> <form method="post" action=""> <div class="int"& ...

  3. ext3文件系统目录限制问题

    昨晚排查了在KVM的build系统中的一个问题,跟踪到后面发现在一个目录下mkdir创建目录失败.我手动试了一下,提示如下:cannot create directory `/home/master/ ...

  4. C#入门经典第四章-流程控制-1

    布尔类型:

  5. List和ArrayList之间转换的例子

    package Test01; import java.util.ArrayList; import java.util.Arrays; import java.util.List; public c ...

  6. Bootstrap 容器(Container)及网格说明-(二)

    1.容器(Container) 2.网格 来自为知笔记(Wiz)

  7. java程序中抛出异常的两种方式,及异常抛出的顺序

    在java中,会经常遇到异常,java提供了两种抛出异常的方式. 方式一: throws ,抛出具体代码中的异常,这种方式编译器都会提示,举例: public static void main(Str ...

  8. javascript类的继承

    1.构造函数方式写类,通过方法调用复制父类属性/字段到子类 实现继承 这里父类,子类都采用构造函数方式写,不用原型.子类调用父类函数来复制父类的属性. 1 2 3 4 5 6 7 8 9 10 11 ...

  9. 那些学些网址_jquery初学知识

    http://www.cnblogs.com/mingmingruyuedlut/archive/2011/10/18/2216553.html(ajax)http://www.enet.com.cn ...

  10. web.xml的启动顺序

    1. context-param 2. Listener 3. Filter 4. servlet <?xml version="1.0" encoding="UT ...