题目大意:给定一种估算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. PAT1006

    At the beginning of every day, the first person who signs in the computer room will unlock the door, ...

  2. 困扰你的private static final long serialVersionUID

    很多时候一个新手在写代码的时候,往往你的IDE就会告诉你一个警告 然后你点击处理这个警告之后,它就会默认给你的类生成一个 private static final long serialVersion ...

  3. hdu_4352_XHXJ's LIS(数位DP+状态压缩)

    题目连接:hdu_4352_XHXJ's LIS 题意:这题花大篇篇幅来介绍电子科大的一个传奇学姐,最后几句话才是题意,这题意思就是给你一个LL范围内的区间,问你在这个区间内最长递增子序列长度恰为K的 ...

  4. HTML的TextArea标记跟随文本内容自动设置高度

    js <textarea name="textarea" id="textarea" style='overflow-y: hidden;height:2 ...

  5. jsp自动刷新(转)

    1.页面自动刷新:把如下代码加入<head>区域中<meta http-equiv="refresh" content="20">,其中 ...

  6. CASpringAnimation

    iOS9新出现的 /** Subclass for mass-spring animations. */ @interface CASpringAnimation : CABasicAnimation ...

  7. webView进度条

    self.progress = [[NJKWebViewProgress alloc] init]; self.webView.delegate = self.progress; __weak typ ...

  8. ntopng汉化记录

    对应版本为 ntopng-1.2.0_r8116.tgz 1.

  9. 为图片存储而作——记一次UEditor源码的修改

    本文版权归博客园和作者吴双本人共同所有.  写在前面 这是一个数据爆发的网络时代,大家习惯于浏览图文直观带给我们的快速信息.大图片的存储和浏览经常会成为Web服务器的瓶颈.试想如果你的Web服务器依然 ...

  10. 1317: Square(DFS+剪枝)

    Description Given a set of sticks of various lengths, is it possible to join them end-to-end to form ...