性能评估
2015-12-16 10:21
344 查看
题目描述:Amtel has announced that it will release a 128-bit computer chip by 2010, a 256-bit computer by 2020, and so on, continuing its strategy of doubling the word-size every ten years. (Amtel released a 64-bit computer in 2000, a 32-bit computer in 1990, a 16-bit computer in 1980, an 8-bit computer in 1970, and a 4-bit computer, its first, in 1960.)
Amtel will use a new benchmark - the Factstone - to advertise the vastly improved capacity of its new chips. The Factstone rating is defined to be the largest integer n such that n! can be represented as an unsigned integer in a computer word.
输入:Given a year 1960 ≤ y ≤ 2160, what will be the Factstone rating of Amtel’s most recently released chip?
输出:For test, there is one line of input containing y. For each test case, output a line giving the Factstone rating.
示例:
输入: 1960
输出: 3
(解释:因为1960年计算机是支持4位,其中的最大的无符号数为(全为1):15;3的阶乘为6,4的阶乘为24,故这里的n=3)
思考:
1、阶乘数据太大,2的高次方数据也太大。
所以考虑使用对数简化计算。
2、float比double有更大精度误差,所以使用double类型。
浮点的作差规范做法:
Amtel will use a new benchmark - the Factstone - to advertise the vastly improved capacity of its new chips. The Factstone rating is defined to be the largest integer n such that n! can be represented as an unsigned integer in a computer word.
输入:Given a year 1960 ≤ y ≤ 2160, what will be the Factstone rating of Amtel’s most recently released chip?
输出:For test, there is one line of input containing y. For each test case, output a line giving the Factstone rating.
示例:
输入: 1960
输出: 3
(解释:因为1960年计算机是支持4位,其中的最大的无符号数为(全为1):15;3的阶乘为6,4的阶乘为24,故这里的n=3)
思考:
1、阶乘数据太大,2的高次方数据也太大。
所以考虑使用对数简化计算。
2、float比double有更大精度误差,所以使用double类型。
浮点的作差规范做法:
#define eps 1e-8 double a, b; while(a - b > eps) {//两个浮点数作差小于某个很小的数,就可以认为他们相等了。 }
#include <stdio.h> #include <math.h> int main() { int y; scanf("%d", &y); double bit = (y - 1960) / 10; bit = pow(2, bit + 2); int i = 1; while (bit > log2(i)) { bit -= log2(i); i++; } i--; printf("%d\n", i); return 0; }
相关文章推荐
- 代码编辑器Sublime Text 3 免费使用方法与简体中文汉化包下载
- Ming Rpc
- .top域名总量15强:14家净增长 西数涨幅第五
- 数据库读写分离的性能分析
- [LeetCode]112. Maximum Subarray最大和连续子序列
- JS 跳转到指定链接
- linux下QT初试
- 属性动画Animator学习
- OC学习篇之---Foundation框架中的其他类(NSNumber,NSDate,NSExcetion)
- [LeetCode]112. Maximum Subarray最大和连续子序列
- 理解GRUB2工作原理及配置选项与方法
- 一个经典例子让你彻彻底底理解java回调机制
- 机器学习--岭回归与偏最小二乘
- 调用一个UITableview的一个代理的方法,实现UITableview重载
- java线上调试小结
- MYSQL 环境变量添加
- 利用mmSeg4j分词实现网页文本倾向性分析
- java 包装类
- Android摄像头 怎么搞?
- Android TabHost取消默认加载第一个tab的问题