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++,并 ...
随机推荐
- CentOS 7 64位 安装 PostgreSQL 9.2整理
centos版本 LSB Version: :core-4.1-amd64:core-4.1-noarchDistributor ID: CentOSDescription: CentOS Linux ...
- python之设置小数保留位数
python之设置小数保留位数 test.py: a = [3,4,4,4,6,4] average1 = float(sum(a)/len(a)) average2 =round(average1, ...
- JAVA 遍历文件夹下的所有文件(递归调用)
package file; import java.io.File; public class Test1 { public static void main(String[] args) { Str ...
- java 常用的几个配置
1.保存代码格式化,打勾即可 2.如何让eclipse像vs那样自动提示,在打勾的地方加入 abcdefghijklmnopqrstuvwxyz.即可
- 面向对象 - 1.封装之如何实现属性的隐藏/2.封装的意义/3.封装与扩展性/4.property的使用
1.封装之如何实现属性的隐藏封装: __x=1 # 把数据属性隐藏 (如何实现隐藏) 类定义阶段 __开头发生了变形 __x --> _A__x特点: 1.在类外部无法直接:obj.__Attr ...
- 【我的Android进阶之旅】 Android Studio插件之Jenkins插件介绍
一Jenkins插件功能介绍 1Jenkins任务列表 2切换Jenkins分组 3构建Jenkins任务 4进入构建Jenkins任务的页面 5进入最后一次构建Jenkins任务的页面 6增加Jen ...
- (4.1)SQL Server Browser 与动态端口
转自:http://blog.51cto.com/jimshu/1120295 一.启用TCP端口 1.启用TCP/IP协议 打开SSCM(SQL Server Configuration Manag ...
- Android 成功 使用GPS获取当前地理位置(解决getLastKnownLocation 返回 null)
最近遇到一个比较棘手的问题:使用GPS定位无法获取当前的地理位置,即getLastKnownLocation方法始终返回null. 后来一篇博文 getLastKnownLocation()返回n ...
- Go 结构体和map等数据结构转json字符串
Go语言中使用json包中的 Marshal() 函数将数据结构转成json字符串,源代码: func Marshal(v interface{}) ([]byte, error) { e := ne ...
- C# 调用win api获取chrome浏览器中地址
//FindWindow 查找窗口 //FindWindowEx查找子窗口 //EnumWindows列举屏幕上的所有顶层窗口,如果回调函数成功则返回非零,失败则返回零 //GetWindowText ...