24h購物| | PChome| 登入
2012-05-13 16:44:09| 人氣681| 回應0 | 上一篇 | 下一篇

[UVA][Math] 545 - Heads

推薦 0 收藏 0 轉貼0 訂閱站台


 Heads 

The probability of n heads in a row tossing a fair coin is 2-n

Input 

The first line of the input contains an integer r. Then r lines containing each one an integer number n. The valueof n is as follows:$0< n le 9000$.

Output 

Print r lines each with the value of 2-n for the given values of n, using the format:


2^-n = x.xxxE-y


where each x is a decimal digit and each y is a decimal integer with no leading zeroes or spaces.

Sample Input 

3
8271
6000
1

Sample Output 

2^-8271 = 1.517E-2490
2^-6000 = 6.607E-1807
2^-1 = 5.000E-1



#include <stdio.h>
#include <math.h>
int main() {
int t, n;
scanf("%d", &t);
while(t--) {
scanf("%d", &n);
int e = (int)floor(-n*log10(2));
printf("2^%d = %.3lfE%d\n", -n, pow(10, -n*log10(2)-e), e);
}
return 0;
}

台長: Morris
人氣(681) | 回應(0)| 推薦 (0)| 收藏 (0)| 轉寄
全站分類: 不分類 | 個人分類: UVA |
此分類下一篇:[UVA][最小覆蓋圓] 10005 - Packing polygons
此分類上一篇:[UVA][二分圖] 11045 - My T-shirt suits me

是 (若未登入"個人新聞台帳號"則看不到回覆唷!)
* 請輸入識別碼:
請輸入圖片中算式的結果(可能為0) 
(有*為必填)
TOP
詳全文