C. Hexadecimal's Numbers

题目连接:

http://www.codeforces.com/contest/9/problem/C

Description

One beautiful July morning a terrible thing happened in Mainframe: a mean virus Megabyte somehow got access to the memory of his not less mean sister Hexadecimal. He loaded there a huge amount of n different natural numbers from 1 to n to obtain total control over her energy.

But his plan failed. The reason for this was very simple: Hexadecimal didn't perceive any information, apart from numbers written in binary format. This means that if a number in a decimal representation contained characters apart from 0 and 1, it was not stored in the memory. Now Megabyte wants to know, how many numbers were loaded successfully.

Input

Input data contains the only number n (1 ≤ n ≤ 109).

Output

Output the only number — answer to the problem.

Sample Input

10

Sample Output

2

Hint

题意

问你小于等于n的数里面,有多少个只由0和1组成的

题解:

感觉上没多少个数嘛,那就直接dfs就好了啦

代码

#include<bits/stdc++.h>
using namespace std;
long long n;
map<int,int> vis;
long long ans = 0;
void dfs(long long x)
{
if(x>n)return;
if(vis[x])return;
vis[x]=1;
ans++;
dfs(x*10);
dfs(x*10+1);
}
int main()
{
cin>>n;
dfs(1);
cout<<ans<<endl;
}

Codeforces Beta Round #9 (Div. 2 Only) C. Hexadecimal's Numbers dfs的更多相关文章

  1. Codeforces Beta Round #80 (Div. 2 Only)【ABCD】

    Codeforces Beta Round #80 (Div. 2 Only) A Blackjack1 题意 一共52张扑克,A代表1或者11,2-10表示自己的数字,其他都表示10 现在你已经有一 ...

  2. Codeforces Beta Round #83 (Div. 1 Only)题解【ABCD】

    Codeforces Beta Round #83 (Div. 1 Only) A. Dorm Water Supply 题意 给你一个n点m边的图,保证每个点的入度和出度最多为1 如果这个点入度为0 ...

  3. Codeforces Beta Round #79 (Div. 2 Only)

    Codeforces Beta Round #79 (Div. 2 Only) http://codeforces.com/contest/102 A #include<bits/stdc++. ...

  4. Codeforces Beta Round #77 (Div. 2 Only)

    Codeforces Beta Round #77 (Div. 2 Only) http://codeforces.com/contest/96 A #include<bits/stdc++.h ...

  5. Codeforces Beta Round #76 (Div. 2 Only)

    Codeforces Beta Round #76 (Div. 2 Only) http://codeforces.com/contest/94 A #include<bits/stdc++.h ...

  6. Codeforces Beta Round #75 (Div. 2 Only)

    Codeforces Beta Round #75 (Div. 2 Only) http://codeforces.com/contest/92 A #include<iostream> ...

  7. Codeforces Beta Round #74 (Div. 2 Only)

    Codeforces Beta Round #74 (Div. 2 Only) http://codeforces.com/contest/90 A #include<iostream> ...

  8. Codeforces Beta Round #73 (Div. 2 Only)

    Codeforces Beta Round #73 (Div. 2 Only) http://codeforces.com/contest/88 A 模拟 #include<bits/stdc+ ...

  9. Codeforces Beta Round #72 (Div. 2 Only)

    Codeforces Beta Round #72 (Div. 2 Only) http://codeforces.com/contest/84 A #include<bits/stdc++.h ...

随机推荐

  1. 安全测试===CSRF攻击简介

    http://www.cnblogs.com/hyddd/archive/2009/04/09/1432744.html

  2. 2016 ACM ICPC Asia Region - Tehran

    2016 ACM ICPC Asia Region - Tehran A - Tax 题目描述:算税. solution 模拟. B - Key Maker 题目描述:给出\(n\)个序列,给定一个序 ...

  3. Tutorial 7: Schemas & client libraries

    转载自:http://www.django-rest-framework.org/tutorial/7-schemas-and-client-libraries/ Tutorial 7: Schema ...

  4. SYN Flood攻击及防御方法 (转)

    原文连接:http://blog.csdn.net/bill_lee_sh_cn/article/details/6065704 一.为什么Syn Flood会造成危害      这要从操作系统的TC ...

  5. python爬取网易云音乐歌单音乐

    在网易云音乐中第一页歌单的url:http://music.163.com/#/discover/playlist/ 依次第二页:http://music.163.com/#/discover/pla ...

  6. serial minicom

    这是一篇讲述串口很好的入门教程: http://users.ece.utexas.edu/~valvano/Volume1/E-Book/C11_SerialInterface.htm 如何显示串口数 ...

  7. 寻找并输出11~999之间的回文数m

    寻找并输出11~999之间的数m,它满足m.m2和m3均为回文数. 回文:各位数字左右对称的整数. 例如:11满足上述条件 112=121,113=1331 判断一个数是否是回文数的方法:求该数的反序 ...

  8. WinPhone8 开发(一)[SDK安装+新建项目]

    微软 WinPhone8 开发 winphone8 SDK下载地址,见博客:http://blog.csdn.net/attagain/article/details/8509511 SDK安装界面: ...

  9. 15、Spark Streaming源码解读之No Receivers彻底思考

    在前几期文章里讲了带Receiver的Spark Streaming 应用的相关源码解读,但是现在开发Spark Streaming的应用越来越多的采用No Receivers(Direct Appr ...

  10. gVim 启动时窗口自动居中

    最近折腾 vim, 除了配置巨麻烦外, 另一个很蛋疼的就是窗口位置问题了, 折腾了半天无法启动时自动居中, 找遍各地也只有保存上次位置, 下次启动时恢复的方法 废话不多说, 直接上代码, 丢到 vim ...