UVALive 6527 Counting ones dfs(水
题目链接:点击打开链接
#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(水的更多相关文章
- poj1564 Sum It Up dfs水题
题目描述: Description Given a specified total t and a list of n integers, find all distinct sums using n ...
- Openjudge1388 Lake Counting【DFS/Flood Fill】
http://blog.csdn.net/c20182030/article/details/52327948 1388:Lake Counting 总时间限制: 1000ms 内存限制: ...
- POJ2386 Lake Counting 【DFS】
Lake Counting Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 20782 Accepted: 10473 D ...
- POJ_2386 Lake Counting (dfs 错了一个负号找了一上午)
来之不易的2017第一发ac http://poj.org/problem?id=2386 Lake Counting Time Limit: 1000MS Memory Limit: 65536 ...
- hdu 3887 Counting Offspring dfs序+树状数组
Counting Offspring Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...
- 【wikioi】1229 数字游戏(dfs+水题)
http://wikioi.com/problem/1229/ 赤裸裸的水题啊. 一开始我认为不用用完全部的牌,以为爆搜会tle.. 可是我想多了. 将所有状态全部求出,排序后暴力判断即可. (水题有 ...
- HDU 2952 Counting Sheep(DFS)
题目链接 Problem Description A while ago I had trouble sleeping. I used to lie awake, staring at the cei ...
- Oil Deposits(dfs水)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1241 Oil Deposits Time Limit: 2000/1000 MS (Java/Othe ...
- Poj2386 Lake Counting (DFS)
Lake Counting Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 49414 Accepted: 24273 D ...
随机推荐
- 第一章、zabbix安装
前言: 注意:本文不涉及性能测试.性能优化中的监控,所有文字的出发点都是日常运维监控. 在开始之前,我们还是先统一下认识:要监控一个对象,需要掌握哪些东西呢? 监控对象的理解:要监控的对象你是否了解呢 ...
- CF 420B Online Meeting 模拟题
只是贴代码,这种模拟题一定要好好纪念下 TAT #include <cstdio> #include <cstring> #include <algorithm> ...
- CSU 1510 Happy Robot
1510: Happy Robot Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 19 Solved: 7 Description Input The ...
- PatentTips - Compare and exchange operation using sleep-wakeup mechanism
BACKGROUND Typically, a multithreaded processor or a multi-processor system is capable of processing ...
- Spring-statemachine给end状态设置action
Spring-statemachine版本:当前最新的1.2.3.RELEASE版本 builder.configureStates() .withStates() .initial(generate ...
- Invalid command 'WSGIScriptAlias', perhaps misspelled or defined by a module not included in the ser
没有Include wsgi,执行: sudo a2enmod wsgi 可能出现以下的错误 ERROR: Module mod-wsgi does not exist! 安装 libapache2- ...
- python学习之--SyntaxError: Non-ASCII character '\xe5'
在安装好eclipse之后试了一下 创建了了一个pydev project package.module 在test.py中编写最简单的命令 print "helloworld" ...
- Haproxy压测
目的:测试Haproxy压测情况 环境: Ha服务器:8核16G虚机,后端6个2核4G,压测客户端3个2核4G 安装和优化: 一.Haproxy #cd /opt/soft #wget http:// ...
- caioj1443:第k小的数Ⅲ
[传送门:caioj1443] 简要题意: 给出一颗n个点的树,给出每个点的权值,再给出n-1条边,有m个询问,每个询问输入x,y,k,输出第x节点到第y节点的路径上第k大的点 题解: 这是一道主席树 ...
- 回顾Abstract和Virtual的用法
今天坐班车的时候,突然就想起来这俩个货了:仔细缕缕,居然越缕越乱较: 上代码吧: using System; using System.Collections.Generic; using Syste ...