您的位置:首页 > 其它

zoj 3827(2014牡丹江现场赛 I题 )

2015-09-20 14:47 316 查看

套公式

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

 

# include <iostream>
# include <cstdio>
# include <cstring>
# include <algorithm>
# include <cmath>
# include <queue>
# define LL long long
using namespace std ;

char s[10] ;
const double esp = 1e-9;

int main ()
{
//freopen("in.txt","r",stdin) ;
int T ;
scanf("%d" , &T) ;
while(T--)
{
int n ;
double  p , b ;
scanf("%d %s" , &n , s) ;
if (s[0] == 'b')
b = 2 ;
else if (s[0] == 'n')
b = exp(1.0) ;
else
b = 10 ;
int i ;
double ans = 0 ;
for (i = 0 ; i < n ; i++)
{
scanf("%lf" , &p) ;
if (fabs(p) > esp)
{
p /= 100.0;
ans += p * log(p) / log(b);
}

}
printf("%.12lf\n" , -ans) ;

}

return 0 ;
}
View Code

 

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: