返回题解分享
讨论 / 题解分享/ 帖子详情

01 串的熵(结果填空) - 题解

##### 暴力枚举

#include <cstdio>
#include <cmath>
using namespace std;
int main(){
	int n = 23333333;
	for(int i=1;i<n;i++)
	{
		double a = i *1.0/n; 
		double b = (n-i)*1.0/n;
		double res =0;
		res-=a*log2(a)*i+b*log2(b)*(n-i);
		if(fabs(res-11625907.5798)<0.0001)
		{
			printf("%d\n",i);
			break;
		}
	}
	return 0;
}
0 回复 0 转发 3 喜欢 2 阅读
回复 (0)
默认 最新
暂无回复,快来抢沙发!