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

 1 #include <cstdio>
 2 #include <cmath>
 3 #include <algorithm>
 4 using namespace std;
 5
 6 int gcd(int a, int b)
 7 {
 8     return b == 0 ? a : gcd(b, a%b);
 9 }
10
11 int main()
12 {
13 #ifdef LOCAL
14     freopen("in", "r", stdin);
15 #endif
16     int n;
17     int a[60];
18     while (scanf("%d", &n) && n)
19     {
20         for (int i = 0; i < n; i++)
21             scanf("%d", &a[i]);
22         int cnt = 0;
23         for (int i = 0; i < n-1; i++)
24             for (int j = i+1; j < n; j++)
25             {
26                 int lmax = max(a[i], a[j]);
27                 int lmin = min(a[i], a[j]);
28                 if (gcd(lmax, lmin) == 1)
29                     cnt++;
30             }
31         if (cnt == 0)
32         {
33             printf("No estimate for this data set.\n");
34             continue;
35         }
36         int total = n*(n-1)/2;
37         printf("%.6lf\n", sqrt(6.0*total/cnt));
38     }
39     return 0;
40 }

View Code

转载于:https://www.cnblogs.com/xiaobaibuhei/p/3308066.html

UVa 412 - Pi相关推荐

  1. SparkSql 项目实战 | 各区域热门商品Top3

    数据源 链接:https://pan.baidu.com/s/1lUbGmA10yOgUL4Rz2KAGmw 提取码:yh57 源码在github:https://github.com/lidongl ...

  2. UVA 11752 超级幂

    UVA 11752 超级幂 Z - The Super Powers Time Limit:1000MS     Memory Limit:0KB     64bit IO Format:%lld & ...

  3. UVa 10180 - Rope Crisis in Ropeland!

    题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=41&pa ...

  4. uva live 4394 String painter 间隔dp

    // uva live 4394 String painter // // 问题是,在培训指导dp运动主题,乍一看,我以为只是一点点复杂 // A A磕磕磕,两个半小时后,.发现超过例子.然而,鉴于他 ...

  5. uva 11468 - Substring(AC自己主动机+概率)

    题目链接:uva 11468 - Substring 题目大意:给出一些字符和各自字符相应的选择概率.随机选择L次后得到一个长度为L的字符串,要求该字符串不包括随意一个子串的概率. 解题思路:构造AC ...

  6. uva 10256 The Great Divide (Convex Hull, Simple)

    http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=14&page=sh ...

  7. POJ 3525/UVA 1396 Most Distant Point from the Sea(二分+半平面交)

    Description The main land of Japan called Honshu is an island surrounded by the sea. In such an isla ...

  8. 【UVA 437】The Tower of Babylon(记忆化搜索写法)

    [题目链接]:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_probl ...

  9. uva 725 Division(暴力模拟)

    Division 紫书入门级别的暴力,可我还是写了好长时间 = = [题目链接]uva 725 [题目类型]化简暴力 &题解: 首先要看懂题意,他的意思也就是0~9都只出现一遍,在这2个5位数 ...

最新文章

  1. 【青少年编程】全国青少年软件编程等级考试大纲与说明(Scratch)
  2. c语言1a和$20比较大小,[转载]Compare过程(字符的查询与比较)
  3. 用VS2010构建MASM的编程环境
  4. PHP下socket编程
  5. Linux 编译安装内核
  6. 深入理解 Java 垃圾回收机制
  7. SVN入门:流程简介 安装配置 项目库配置 客户端 上线方案
  8. Android实现侧滑抽屉菜单,android studio自带的抽屉侧滑菜单怎么设置点击事件?还头一回遇到,汗!...
  9. EBS 报表输出PDF时中文乱码
  10. 英文简历 计算机知识,计算机应届生英文简历范文
  11. java文件读写的基本类_java常用工具类(三)—— 文件读取的操作类
  12. 公司新办公楼休息间能看到富士山了
  13. 金蝶徐少春与北大学生分享“最伟大的梦想”
  14. Clang编译Objective-C
  15. 详细的组态王软件与200 Smart PLC网口通信教程
  16. NSA方程式工具利用与分析
  17. 拼多多,是漏洞的损失?还是营销的手段?
  18. Jenkins linux 操作系统一键部署多节点
  19. php7cms手册,phpcms手册下载|
  20. 医疗机构如何成功实施CRM?如下几点是关键因素

热门文章

  1. 一打在2019年亮相的迷人科技项目:飞行汽车、子弹头列车、登月、……
  2. 斯坦福大学科学家研发微型植入式神经刺激器
  3. 腾讯「AI In All」的背后,是开放AI技术能力,探索腾讯应用场景
  4. 写给大忙人看的死锁详解
  5. Facebook Docusaurus 中文文档 安装指南
  6. JNI命令行下编译错误解决方案
  7. shell编程系列15--文本处理三剑客之awk格式化输出printf
  8. AOP埋点从入门到放弃(二)
  9. 《DBA修炼之道:数据库管理员的第一本书》——1.4节评估DBA的工作邀请
  10. ORA-01436: 用户数据中的CONNECT BY 循环