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 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的更多相关文章
- Codeforces Beta Round #80 (Div. 2 Only)【ABCD】
Codeforces Beta Round #80 (Div. 2 Only) A Blackjack1 题意 一共52张扑克,A代表1或者11,2-10表示自己的数字,其他都表示10 现在你已经有一 ...
- Codeforces Beta Round #83 (Div. 1 Only)题解【ABCD】
Codeforces Beta Round #83 (Div. 1 Only) A. Dorm Water Supply 题意 给你一个n点m边的图,保证每个点的入度和出度最多为1 如果这个点入度为0 ...
- Codeforces Beta Round #79 (Div. 2 Only)
Codeforces Beta Round #79 (Div. 2 Only) http://codeforces.com/contest/102 A #include<bits/stdc++. ...
- Codeforces Beta Round #77 (Div. 2 Only)
Codeforces Beta Round #77 (Div. 2 Only) http://codeforces.com/contest/96 A #include<bits/stdc++.h ...
- Codeforces Beta Round #76 (Div. 2 Only)
Codeforces Beta Round #76 (Div. 2 Only) http://codeforces.com/contest/94 A #include<bits/stdc++.h ...
- Codeforces Beta Round #75 (Div. 2 Only)
Codeforces Beta Round #75 (Div. 2 Only) http://codeforces.com/contest/92 A #include<iostream> ...
- Codeforces Beta Round #74 (Div. 2 Only)
Codeforces Beta Round #74 (Div. 2 Only) http://codeforces.com/contest/90 A #include<iostream> ...
- Codeforces Beta Round #73 (Div. 2 Only)
Codeforces Beta Round #73 (Div. 2 Only) http://codeforces.com/contest/88 A 模拟 #include<bits/stdc+ ...
- Codeforces Beta Round #72 (Div. 2 Only)
Codeforces Beta Round #72 (Div. 2 Only) http://codeforces.com/contest/84 A #include<bits/stdc++.h ...
随机推荐
- SuSE Linux Supervisor的安装与使用案例
建议使用 root 管理员账户操作 1.安装工具 1.apache 2..Net Core(dotnet-sdk-2.0) 3.Supervisor(进程管理工具,目的是服务器一开机就启动服务器 ...
- 终止函数 atexit()
函数名: atexit 头文件:#include<stdlib.h> 功 能: 注册终止函数(即main执行结束后调用的函数) 用 法: int atexit(void (*f ...
- request机制
每个框架中都有处理请求的机制(request),但是每个框架的处理方式和机制是不同的 为了了解Flask的request中都有什么东西,首先我们要写一个前后端的交互 基于HTML + Flask 写一 ...
- hive学习(五) 应用案例
1.实现struct数据结构例子 1.1创建student表 create table student( id int, info struct<name:string,age:int> ...
- Java学习(运算符,引用数据类型)
一. 运 算 符 1.算数运算符 运算符是用来计算数据的符号.数据可以是常量,也可以是变量.被运算符操作的数我们称为操作数. 算术运算符最常见的操作就是将操作数参与数学计算,具体使用看下图 ...
- 小甲鱼C++笔记(下)25-48
二十五 二十六 二十七 重载 运算符重载 1. 作为成员函数 #include <iostream> using namespace std; class Add { private ...
- 免费的.NET混淆和反编译工具
免费的.NET代码混淆工具: Eazfuscator.NET http://www.foss.kharkov.ua/g1/projects/eazfuscator/dotnet/Default.as ...
- spring_150909_hibernate_id_table
1.新建java工程:spring_150909_hibernate_id_table,如下图所示: 2.建DogPet实体类: package com.spring.model; import ja ...
- python的多线程threading
多线程threading 1.Thread创建线程: 上代码: #!/usr/bin/env python3 import threading import time def A(): t_name ...
- 最大公约数or最小公倍数
最大公约数or最小公倍数 import org.junit.Test; public class 最大公约数or最小公倍数 { public int maxGYS(int m,int n) { int ...