ZOJ3827-水题-I
来源:互联网 发布:焦作知行纳米 编辑:程序博客网 时间:2024/06/06 09:41
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3827
直接划水就好了。
三种方法,计算三种logn。
比赛的时候没看懂题,,队友写的。。。
不太清楚eps是干嘛的
自己补的。
#include <bits/stdc++.h>using namespace std;/*线段树主要应用于下列情况1 区间查询*/const int maxn=2000;int main(){ int t; int a[maxn]; int n; string s; double sum=0; scanf("%d",&t); while(t--){ cin>>n; cin>>s; sum=0; for(int i=0;i<n;i++){ cin>>a[i]; sum+=a[i]; } double ans=0; if(s=="bit") for(int i=0;i<n;i++){ //if(!a[i]) continue; ans+=-(a[i]*1.0/sum*1.0)*log2((a[i]*1.0)/sum*1.0); } else if(s=="nat") for(int i=0;i<n;i++){ if(!a[i]) continue; ans+=-(a[i]*1.0/sum*1.0)*log((a[i]*1.0)/sum*1.0); } else if(s=="dit") for(int i=0;i<n;i++){ if(!a[i]) continue; ans+=-(a[i]*1.0/sum*1.0)*log10((a[i]*1.0)/sum*1.0); } printf("%.12f\n",ans); } return 0;}
队友写的
#include <iostream>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <algorithm>#include <math.h>#define E 2.718281828459#define EPS 1e-12#include <map>using namespace std;map<string,double>mp;double a[105];int main(){ mp["bit"]=2;mp["nat"]=E;mp["dit"]=10;mp["digit"]=10; int t; scanf("%d",&t); while(t--) { int n; string str; scanf("%d",&n); cin>>str; double b=mp[str]; //cout<<"b="<<b<<endl; double sum=0; if(b==E) { for(int i=0;i<n;i++) { scanf("%lf",&a[i]); a[i]/=100; if(a[i]!=0) sum-=a[i]*log(a[i]); else sum-=EPS*log(EPS); } } else if(b==10) { for(int i=0;i<n;i++) { scanf("%lf",&a[i]); a[i]/=100; if(a[i]!=0) sum-=a[i]*log10(a[i]); else sum-=EPS*log10(EPS); } } else if(b==2) { for(int i=0;i<n;i++) { scanf("%lf",&a[i]); a[i]/=100; if(a[i]!=0) sum-=a[i]*log(a[i])/log(b); else sum-=EPS*log(EPS)/log(b); } } printf("%.12lf\n",sum); } return 0;}
阅读全文
0 0
- ZOJ3827-水题-I
- ZOJ3827 ACM-ICPC 2014 亚洲区域赛牡丹江现场赛I题 Information Entropy 水题
- ZOJ3827 Information Entropy(模拟水题)
- I Think I Need a Houseboat(水题)
- I - In Touch-Gym 100492I-水题
- hdu4608 - I-number(水题)
- Bedtime Reading I--水题
- codeforces 589I(水题)
- I
- I
- ++i
- I
- I
- i
- ++i
- i++
- (++i) + (++i) + (++i) + (++i)
- i++
- 使用Gson获取签到记录
- Digit Counting (P57)/ UVA
- hive编程笔记---多表关联使用感想
- vue中watch的使用时机,如何在初始化后再使用?
- java 多态提高篇
- ZOJ3827-水题-I
- bzoj3886[Usaco2015 Jan]Moovie Mooving 状压DP
- HTTPShouldUsePipelining 解释
- c3p0-0.9.1.2.jar与c3p0-0.9.5.2.jar
- centos 6.8 安装nginx
- 2 3 5 7的倍数 【容斥】
- 使用h5+API实现安卓端连按两次返回键退出app
- 什么是机器学习以及什么时候适合使用机器学习?
- java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener