码迷,mamicode.com
首页 > 其他好文 > 详细

UVALive 6527 Counting ones dfs(水

时间:2014-10-30 13:32:20      阅读:159      评论:0      收藏:0      [点我收藏+]

标签:blog   http   io   ar   for   sp   on   2014   log   

题目链接:点击打开链接




#include <cstdio>
#include <vector>
using namespace std;
typedef long long ll;
ll re;
vector<int> p;
void dfs(int dep, int g) {
	if (dep == 0)
		return ;
	if (p[dep-1] == 1) {
		re += (dep-1) * (1ll<< (dep-2));
		re += g * (1ll << (dep-1));
	}
	dfs(dep-1, g+p[dep-1]);
}
ll C(ll x) {
	if (x == 0)
		return 0;
	p.clear();
	re = 0;
	while (x>0) {
		p.push_back(x%2);
		x /= 2;
	}
	for (int i = 0; i < (int)p.size(); ++i)
		re += p[i];
	dfs(p.size(), 0);
	return re;
}
int main() {
	ll A, B;
	while (~scanf("%lld%lld", &A, &B))
		printf("%lld\n", C(B) - C(A-1));
	return 0;
}


UVALive 6527 Counting ones dfs(水

标签:blog   http   io   ar   for   sp   on   2014   log   

原文地址:http://blog.csdn.net/qq574857122/article/details/40618329

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!