HDU 1141

Factstone Benchmark

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 2259    Accepted Submission(s): 1277


Problem Description
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?

There are several test cases. For each test case, there is one line of input containing y. A line containing 0 follows the last test case. For each test case, output a line giving the Factstone rating.
Sample Input
1960
1981
0
Sample Output
3
8

题意:××公司是制造computer的,1960年它造的computer是4bit的,之后每10年翻倍;

有一个衡量computer的标准,就是它最大可以存下n!(无符号位),那么它就是n级;

求x年时该公司的电脑为几级(1960<= x <=2160);

思路:也是求位数的题目,方法类似hdu1018 链接http://www.cnblogs.com/ISGuXing/p/7301041.html

只不过用log2

这道题打表。

代码:

 1 #include<iostream>
 2 #include<stdio.h>
 3 #include<cmath>
 4 #include<algorithm>
 5 #include<math.h>
 6 using namespace std;
 7 int a[350000];
 8 int main(){
 9     double k=0.0;
10     for(int i=1;i<=350000;i++){
11         k+=log2(i);
12         a[i]=(int)k+1;
13     }
14     int year;
15     while(scanf ("%d",&year)&&year!=0){
16         int x=(year-1960)/10;
17         int bit=4*(pow(2,x));
18         int pos=lower_bound(a,a+350000,bit)-a;
19         if(a[pos]>bit){
20             pos--;
21         }
22         cout<<pos<<endl;
23     }
24     return 0;
25 }

 

posted @ 2017-08-07 20:06  ISGuXing  阅读(230)  评论(0编辑  收藏  举报