Codeforces 9C Hexadecimal's Numbers - 有技巧的枚举
2017-08-01 21:35:53
writer:pprp
集训第一天:作为第一道题来讲,说了两种算法,
第一种是跟二进制数联系起来进行分析;
第二种是用深度搜索来做,虽然接触过深度搜索但是这种题型还是我第一次见;
题目:
统计1~n之间有多少数字只由0,1构成
1 ≤ n ≤ 1e9
用深度搜索解决这种问题;
代码如下:
#include <iostream>
#include <map> using namespace std; map<int,int>vis; long long ans = ; int n; //深度搜索,模仿
void dfs(int x)
{
if(x > n)
return;
if(vis[x])
return;
vis[x] = ;
ans++;
dfs(x*);
dfs(x*+);
} int main()
{
cin >> n; dfs(); cout << ans << endl; return ;
}
遇到的问题:不知道为什么用数组来取代map就不能通过,最后还是用了map
Codeforces 9C Hexadecimal's Numbers - 有技巧的枚举的更多相关文章
- Codeforce 9C - Hexadecimal's Numbers
One beautiful July morning a terrible thing happened in Mainframe: a mean virus Megabyte somehow got ...
- Codeforces Beta Round #9 (Div. 2 Only) C. Hexadecimal's Numbers dfs
C. Hexadecimal's Numbers 题目连接: http://www.codeforces.com/contest/9/problem/C Description One beautif ...
- codeforces 9 div2 C.Hexadecimal's Numbers 暴力打表
C. Hexadecimal's Numbers time limit per test 1 second memory limit per test 64 megabytes input stand ...
- [codeforces 55]D. Beautiful numbers
[codeforces 55]D. Beautiful numbers 试题描述 Volodya is an odd boy and his taste is strange as well. It ...
- C. Hexadecimal's Numbers
C. Hexadecimal's Numbers time limit per test 1 second memory limit per test 64 megabytes input stand ...
- CodeForces - 1245A Good ol' Numbers Coloring (思维)
Codeforces Round #597 (Div. 2 Consider the set of all nonnegative integers: 0,1,2,-. Given two integ ...
- CodeForces 682A Alyona and Numbers (水题)
Alyona and Numbers 题目链接: http://acm.hust.edu.cn/vjudge/contest/121333#problem/A Description After fi ...
- Codeforces 449D Jzzhu and Numbers
http://codeforces.com/problemset/problem/449/D 题意:给n个数,求and起来最后为0的集合方案数有多少 思路:考虑容斥,ans=(-1)^k*num(k) ...
- 9 C. Hexadecimal's Numbers
题目链接 http://codeforces.com/contest/9/problem/C 题目大意 输入n,计算出n之内只有0和1组成的数字的数量 分析 k从1开始,只要小于n,就给sum++,并 ...
随机推荐
- python中 将字符串和字典的相互转换
1.首先引入json模块 # 引入json模块 import json 2.转换 #JSON到字典转化: dictinfo = json.loads(json_str) # 输出dict类型 字典到J ...
- devmapper: Thin Pool has 162394 free data blocks which is less than minimum required 163840 free data blocks
问题: 制作镜像的时候报错 devmapper: Thin Pool has 162394 free data blocks which is less than minimum required 1 ...
- mysql utf8字符集下使用DES_ENCRYPT
DES_ENCRYPT() 加密字符串后内容为空 改变字符集latin1 可以保存和解密(DES_DECRYPT)
- vim_action
读取文件,显示行号 nl -a.txt brace expansion 花括号扩展 echo a{A{1,2},B{3,4}}b mkdir {2009...2011}-0{1...9} {2009. ...
- elastic search远程测试
elastic search远程测试 推荐:elastic官方教程:https://www.elastic.co/guide/en/elasticsearch/reference/6.2/index. ...
- 11.Query an Array of Embedded Documents-官方文档摘录
总结 1.插入数据 db.inventory.insertMany( [ { item: "journal", instock: [ { warehouse: "A&qu ...
- Linux network 资料链接
1.iptables 基础 https://wiki.centos.org/HowTos/Network/IPTables 2.HOWTOs on netfilter site http://www. ...
- EJB远程客户端和本地客户端
在客户端中使用企业bean 企业bean的客户端通过依赖注入或JNDI查询的方式获得对企业bean实例的引用. 依赖注入是获得对企业bean实例的引用的最简便的方法. (紧耦合的bean之间相互依赖, ...
- 利用VMware克隆linux虚拟机需要注意的事项
利用VMware克隆虚拟机需要注意的问题 2018年03月30日 18:20:29 温文尔雅的流氓 阅读数:1343更多 个人分类: linux 版权声明:本文为博主原创文章,未经博主允许不得转载 ...
- Delphi 正则表达式语法(8): 引用子表达式 - 也叫反向引用
Delphi 正则表达式语法(8): 引用子表达式 - 也叫反向引用 //准备: 我们先写一个搜索所有英文单词的表达式 var reg: TPerlRegEx; begin reg := TP ...