POJ 2661 Factstone Benchmark (斯特灵公式)
来源:互联网 发布:园林设计软件有哪些 编辑:程序博客网 时间:2024/06/05 06:57
题目:http://poj.org/problem?id=2661
题意:1960年计算机是4bit,1970年更新为8bit,1980年更新为16bit,以后每十年更新一次(翻一倍),给你一个年份n(1960<=n<=2160),求出该年份计算机能计算出来的最大阶乘(不溢出)。
分析:数据范围比较小,算出21个数即可。直接算阶乘等了几分钟还有4个数没出完。利用斯特灵公式算阶乘,打表。
斯特灵公式是一条用来取n阶乘近似值的数学公式。一般来说,当n很大的时候,n阶乘的计算量十分大,所以斯特灵公式十分好用,而且,即使在
n很小的时候,斯特灵公式的取值已经十分准确。
公式为:
比较阶乘和该年份的可算的最大数,利用log2()函数。打表代码:
#include <iostream>#include <cstdio>#include <cmath>using namespace std;#define e 2.718281828459#define pi 3.1415926535898bool cmp(int year,int fac){double b=0.500*log2(pi*2.0*fac)+fac*log2(0.0+fac/e);return (1<<((year-1960)/10))*4>b;}int main(){int mid,up,down,ans;int year;for(int year=1960;year<=2160;year+=10){for(int i=1;;i++){if(cmp(year,i))ans=i;elsebreak;}printf("%d",ans);printf(",\n");}return 0;}
提交代码:
#include <iostream>#include <cstdio>using namespace std;int a[]={3,5,8,12,20,34,57,98,170,300,536,966,1754,3210,5910,10944,20366,38064,71421,134480,254016};int main(){int n;while(scanf("%d",&n),n)printf("%d\n",a[(n-1960)/10]);return 0;}
0 0
- POJ 2661 Factstone Benchmark (斯特灵公式)
- POJ 2661 Factstone Benchmark
- POJ-2661-Factstone Benchmark
- POJ 2661 Factstone Benchmark
- poj-2661-Factstone Benchmark
- poj--2661 Factstone Benchmark
- POJ 2661 Factstone Benchmark 斯特林(stirling公式)应用
- POJ 2661 Factstone Benchmark 数学题
- zoj 2545 || poj 2661 Factstone Benchmark
- uva 10916 poj 2661 Factstone Benchmark
- POJ 2661-Factstone Benchmark(log()的应用)
- POJ 2661 Factstone Benchmark (log2的故事)
- poj 2661 Factstone Benchmark 取对数
- poj-2661-Factstone Benchmark(对数log()的应用or斯特林公式求n!的位数)
- POJ 2661 Factstone Benchmark 求最大阶乘的位数
- 2661 Factstone Benchmark 解题报告
- Factstone Benchmark
- Factstone Benchmark
- Java入门到精通——调错篇之Spring2.5使用AOP时报错only available on JDK 1.5 and higher
- 00-自测2. 素数对猜想 (20)
- 00-自测3. 数组元素循环右移问题 (20)
- 00-自测4. Have Fun with Numbers (20)
- 安卓编程 使EditText无法输入只能进行复制等操作
- POJ 2661 Factstone Benchmark (斯特灵公式)
- 00-自测5. Shuffling Machine (20)
- C++ 去学就好
- Linked List Cycle II
- JavaScript with关键字
- 苹果取代Windows成为了最脆弱了系统
- Swift UI专项训练1 交互
- 链表、头指针、头结点、第一个结点的区别与联系
- 面向对象的总结(2)