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;
}
时间: 2024-08-27 18:49:33

UVALive 6527 Counting ones dfs(水的相关文章

UVALive 6602 Counting Lattice Squares 【几何】【机智】

题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=4613 题目大意:给你一个n*m的矩阵格子,在这n*m的矩阵格子中要你选出四个点,形成一个正方形,让正方形的面积为奇数,问可以形成多少个这样的正方形. 题目思路:从每一个奇数开始作为一个基本单元. 面积     边 能组成的正方形: 1*1      1      

POJ2386 Lake Counting 【DFS】

Lake Counting Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 20782   Accepted: 10473 Description Due to recent rains, water has pooled in various places in Farmer John's field, which is represented by a rectangle of N x M (1 <= N <= 10

Openjudge1388 Lake Counting【DFS/Flood Fill】

http://blog.csdn.net/c20182030/article/details/52327948 1388:Lake Counting 总时间限制:   1000ms   内存限制:   65536kB 描述 Due to recent rains, water has pooled in various places in Farmer John's field, which is represented by a rectangle of N x M (1 <= N <= 1

POJ 2248 Addition Chains dfs(水)

题意:给出n 构成出满足下列条件 长度最小的数列a[0]=1,a[m]=n, a[0]<a[1]<..<a[m]每个下标k都存在(i,j<k) 满足:a[k]=a[i]+a[j] n<=100 枚举长度 dfs爆搜+剪枝 水过, #include <iostream> #include <cstring> #include <cstdio> using namespace std; const int N=2e5+20; int n,a[N

poj 2386  Lake Counting DFS

n*m的矩阵W是水 .是地问有多少池塘池塘的定义是:W通过 八个 方向连接成的一片算作是一个池塘 样例输入中,有左上.左下.右侧三片连接在一起的W因而样例输出给出了3个池塘的答案 #include <cstdio> #include <iostream> #define N 110 using namespace std; int n,m; char s[N][N]; void dfs(int x,int y) { s[x][y]='.'; int i,j; for(i=-1; i

UVALive 5058 Counting BST 数学

B - Counting BST Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit Status Practice UVALive 5058 Description Binary Search Tree (BST) is a rooted binary tree data structure which has following properties: Left subtree conta

hdu 3887 Counting Offspring dfs序+树状数组

Counting Offspring Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Problem Description You are given a tree, it’s root is p, and the node is numbered from 1 to n. Now define f(i) as the number of nodes whose numbe

POJ2386 Lake Counting 图DFS

找出有多少个"水洼"(W的联通块) Sample Input 10 12 W--..WW. .WWW-..WWW -.WW-WW. ---WW. ---W.. ..W--W.. .W.W-..WW. W.W.W-..W. .W.W--W. ..W--.W. Sample Output 3 解题思路 DFS 代码 #include <cstdio> #include <cstring> #include <algorithm> using namesp

POJ 2386 Lake Counting(DFS)

题意:有一个大小为N×M的园子,雨后积起了水.八连通的积水被认为是连在一起的.求园子里一共有多少水洼? * * * * W*    (八连通指的就是左图中相对W的*的部分) * * * Sample Input 10 12 W........WW. .WWW.....WWW ....WW...WW. .........WW. .........W.. ..W......W.. .W.W.....WW. W.W.W.....W. .W.W......W. ..W.......W. Sample O