设为首页 加入收藏

TOP

poj 3105 Expectation 按位统计
2015-11-21 00:58:10 来源: 作者: 【 】 浏览:1
Tags:poj 3105 Expectation 统计

题意:

给n,求sum(i^j)/(n^2),0<=i,j

分析:

暴力n^2算法肯定超时。这是logn按位统计算法:按位先算出0出现的个数x,则1出现的个数为n-x,再算每位对和的贡献。

代码:

?

//poj 3105
//sep9
#include 
  
   
using namespace std;

int main()
{
	int cases;
	scanf(%d,&cases);
	while(cases--){
		int n;
		double ans=0;
		scanf(%d,&n);
		for(int i=0;i<31;++i){
			int s=1<
   
    >(i+1)<
    
     

?

?

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇leetcode | Implement strStr() |.. 下一篇hdu 3501 Calculation 2

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: