hdu 5524 Subtrees dfs
Subtrees
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
For each case contains a single integer N on a line.(1≤N≤1018)
6
7
8
4
3
5
就是如果左子树和右子树相同只需要遍历一颗子树即可;
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<queue>
#include<algorithm>
#include<stack>
#include<cstring>
#include<vector>
#include<list>
#include<set>
#include<map>
using namespace std;
#define ll long long
#define pi (4*atan(1.0))
#define eps 1e-14
#define bug(x) cout<<"bug"<<x<<endl;
const int N=2e3+,M=4e6+,inf=;
const ll INF=1e18+,mod=1e9+; /// 数组大小 set<ll>ans;
map<ll,ll>si;
ll n;
void dfs(ll x)
{
if(x>n)return;
ll l=x,r=x;
while(l*<=n)l*=;
while(r*+<=n)r=r*+;
if(l==x&&r==x)
{
si[x]=;
ans.insert();
return;
}
if(l<=r)
{
dfs(x*);
si[x]=*si[x*]+;
ans.insert(si[x]);
//cout<<x<<" "<<si[x]<<endl;
}
else
{
dfs(x*);
dfs(x*+);
si[x]=si[x*]+si[x*+]+;
//cout<<x<<" "<<si[x]<<" "<<si[x*2]<<" "<<si[x*2+1]<<endl;
ans.insert(si[x]);
}
}
int main()
{
while(~scanf("%lld",&n))
{
ans.clear();
si.clear();
dfs();
printf("%d\n",ans.size());
}
return ;
}
hdu 5524 Subtrees dfs的更多相关文章
- (树)Subtrees -- hdu -- 5524
http://acm.hdu.edu.cn/showproblem.php?pid=5524 Subtrees Time Limit: 2000/1000 MS (Java/Others) Me ...
- HDU.5692 Snacks ( DFS序 线段树维护最大值 )
HDU.5692 Snacks ( DFS序 线段树维护最大值 ) 题意分析 给出一颗树,节点标号为0-n,每个节点有一定权值,并且规定0号为根节点.有两种操作:操作一为询问,给出一个节点x,求从0号 ...
- HDU 5524:Subtrees
Subtrees Accepts: 60 Submissions: 170 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 13107 ...
- hdu 5727 Necklace dfs+二分图匹配
Necklace/center> 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5727 Description SJX has 2*N mag ...
- hdu 4499 Cannon dfs
Cannon Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4499 D ...
- hdu 1175 连连看 DFS
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1175 解题思路:从出发点开始DFS.出发点与终点中间只能通过0相连,或者直接相连,判断能否找出这样的路 ...
- HDU 5547 Sudoku(DFS)
题目网址:http://acm.hdu.edu.cn/showproblem.php?pid=5547 题目: Sudoku Time Limit: 3000/1000 MS (Java/Others ...
- F - Auxiliary Set HDU - 5927 (dfs判断lca)
题目链接: F - Auxiliary Set HDU - 5927 学习网址:https://blog.csdn.net/yiqzq/article/details/81952369题目大意一棵节点 ...
- hdu 4714 树+DFS
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4714 本来想直接求树的直径,再得出答案,后来发现是错的. 思路:任选一个点进行DFS,对于一棵以点u为 ...
随机推荐
- idea 使用方法
1:设置自定义自动补全,使用$END$代表最后光标所在的位置. http://blog.csdn.net/u012569796/article/details/54694418 2:使用 shift+ ...
- Python安装sqlite3
今天使用PYthon时,发现错误 ImportError: No module named sqlite 这是因为缺少 SQLITE3的缘故. 下面分享一下解决此问题的方法步骤: 1. 查看是Pyth ...
- VMWARE安装centos6 http://www.centoscn.com/image-text/setup/2013/0816/1263.html
http://www.centoscn.com/image-text/setup/2013/0816/1263.html
- Git—使用方法
1.:插件的安装(eclipse LUNA版本之后已经自动集成,不需要安装插件). * 先打开该网页提供了对应版本的EGit,自己选择相应的版本.(http://wiki.eclipse.org/EG ...
- 【Redis学习之一】Redis
环境 虚拟机:VMware 10 Linux版本:CentOS-6.5-x86_64 客户端:Xshell4 FTP:Xftp4 jdk8 一.Redis入门介绍 数据存储的发展:文件存储--> ...
- python3.4学习笔记(七) 学习网站博客推荐
python3.4学习笔记(七) 学习网站博客推荐 深入 Python 3http://sebug.net/paper/books/dive-into-python3/<深入 Python 3& ...
- 计算概论(A)/基础编程练习2(8题)/1:求平均年龄
#include<stdio.h> int main() { // 声明与初始化 , s=, age=; // 输入学生人数 scanf("%d", &n); ...
- bzoj1698 / P1606 [USACO07FEB]白银莲花池Lilypad Pond
P1606 [USACO07FEB]白银莲花池Lilypad Pond 转化为最短路求解 放置莲花的方法如果直接算会有重复情况. 于是我们可以先预处理和已有莲花之间直接互相可达的点,将它们连边(对,忽 ...
- JCTools, 场景特化的并发工具
同上一篇一样,在jmap -histo中发现MpscChunkedArrayQueue类的实例比较多,javadoc看了下,其原来是出自JC Tools,https://github.com/JCTo ...
- Android http通信 HttpURLConnection
post 请求: package com.example.administrator.eschool; import android.os.Bundle; import android.os.Hand ...