UVa 412 - Pi
题目大意:给定一种估算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相关推荐
- SparkSql 项目实战 | 各区域热门商品Top3
数据源 链接:https://pan.baidu.com/s/1lUbGmA10yOgUL4Rz2KAGmw 提取码:yh57 源码在github:https://github.com/lidongl ...
- UVA 11752 超级幂
UVA 11752 超级幂 Z - The Super Powers Time Limit:1000MS Memory Limit:0KB 64bit IO Format:%lld & ...
- UVa 10180 - Rope Crisis in Ropeland!
题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=41&pa ...
- uva live 4394 String painter 间隔dp
// uva live 4394 String painter // // 问题是,在培训指导dp运动主题,乍一看,我以为只是一点点复杂 // A A磕磕磕,两个半小时后,.发现超过例子.然而,鉴于他 ...
- uva 11468 - Substring(AC自己主动机+概率)
题目链接:uva 11468 - Substring 题目大意:给出一些字符和各自字符相应的选择概率.随机选择L次后得到一个长度为L的字符串,要求该字符串不包括随意一个子串的概率. 解题思路:构造AC ...
- uva 10256 The Great Divide (Convex Hull, Simple)
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=14&page=sh ...
- 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 ...
- 【UVA 437】The Tower of Babylon(记忆化搜索写法)
[题目链接]:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_probl ...
- uva 725 Division(暴力模拟)
Division 紫书入门级别的暴力,可我还是写了好长时间 = = [题目链接]uva 725 [题目类型]化简暴力 &题解: 首先要看懂题意,他的意思也就是0~9都只出现一遍,在这2个5位数 ...
最新文章
- 【青少年编程】全国青少年软件编程等级考试大纲与说明(Scratch)
- c语言1a和$20比较大小,[转载]Compare过程(字符的查询与比较)
- 用VS2010构建MASM的编程环境
- PHP下socket编程
- Linux 编译安装内核
- 深入理解 Java 垃圾回收机制
- SVN入门:流程简介 安装配置 项目库配置 客户端 上线方案
- Android实现侧滑抽屉菜单,android studio自带的抽屉侧滑菜单怎么设置点击事件?还头一回遇到,汗!...
- EBS 报表输出PDF时中文乱码
- 英文简历 计算机知识,计算机应届生英文简历范文
- java文件读写的基本类_java常用工具类(三)—— 文件读取的操作类
- 公司新办公楼休息间能看到富士山了
- 金蝶徐少春与北大学生分享“最伟大的梦想”
- Clang编译Objective-C
- 详细的组态王软件与200 Smart PLC网口通信教程
- NSA方程式工具利用与分析
- 拼多多,是漏洞的损失?还是营销的手段?
- Jenkins linux 操作系统一键部署多节点
- php7cms手册,phpcms手册下载|
- 医疗机构如何成功实施CRM?如下几点是关键因素