套公式
Sample Input
3
3 bit
25 25 50 //百分数
7 nat
1 2 4 8 16 32 37
10 dit
10 10 10 10 10 10 10 10 10 10
Sample Output
1.500000000000
1.480810832465
1.000000000000
1 # include <iostream> 2 # include <cstdio> 3 # include <cstring> 4 # include <algorithm> 5 # include <cmath> 6 # include <queue> 7 # define LL long long 8 using namespace std ; 9 10 char s[10] ; 11 const double esp = 1e-9; 12 13 int main () 14 { 15 //freopen("in.txt","r",stdin) ; 16 int T ; 17 scanf("%d" , &T) ; 18 while(T--) 19 { 20 int n ; 21 double p , b ; 22 scanf("%d %s" , &n , s) ; 23 if (s[0] == ‘b‘) 24 b = 2 ; 25 else if (s[0] == ‘n‘) 26 b = exp(1.0) ; 27 else 28 b = 10 ; 29 int i ; 30 double ans = 0 ; 31 for (i = 0 ; i < n ; i++) 32 { 33 scanf("%lf" , &p) ; 34 if (fabs(p) > esp) 35 { 36 p /= 100.0; 37 ans += p * log(p) / log(b); 38 } 39 40 } 41 printf("%.12lf\n" , -ans) ; 42 43 } 44 45 return 0 ; 46 }
时间: 2024-11-10 02:15:01