cf - 01串的问题
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.
Example
10
2
Note
For n = 10 the answer includes numbers 1 and 10.
题目分析 : 给你一个 n ,表示 1 - n 共 n 个数字,问有多少个数字中只含有 0 和 1
思路分析 : 对于一个只含有 01 数字的十进制数字,他一定可以通过这样的变换得来, a*10 和 a*10+1 , 既然有这样的规律,那么写一个深搜就可以直接过了。
代码示例 :
int ans = 0;
ll n; void dfs(ll x){
if (x > n) return;
ans++;
dfs(x*10);
dfs(x*10+1);
} int main() {
cin >> n;
dfs(1);
printf("%d\n", ans); return 0;
}
cf - 01串的问题的更多相关文章
- COGS 862. 二进制数01串【dp+经典二分+字符串】
862. 二进制数01串 ★ 输入文件:kimbits.in 输出文件:kimbits.out 简单对比 时间限制:1 s 内存限制:128 MB USACO/kimbits(译 by ...
- JZOJ P1847:找01串
传送门 DP预处理+贪心 首先设$f[i][j]$表示长度为$i$的01串中有不大于$j$个1,然后显然 $f[i][j]=\sum_{k=1} ^{j} C[i][k]$ $C[i][j]=C[i- ...
- 洛谷P2727 01串 Stringsobits
P2727 01串 Stringsobits 24通过 55提交 题目提供者该用户不存在 标签USACO 难度普及+/提高 提交 讨论 题解 最新讨论 这题的思路是啥啊!!!跪求- 题目背景 考虑 ...
- C++实现01串排序
题目内容:将01串首先按长度排序,长度相同时,按1的个数从少到多进行排序,1的个数相同时再按ASCII码值排序. 输入描述:输入数据中含有一些01串,01串的长度不大于256个字符. 输出描述:重新排 ...
- 01串(dp)
01串 时间限制:1000 ms | 内存限制:65535 KB 难度:2 描述 ACM的zyc在研究01串,他知道某一01串的长度,但他想知道不含有“11”子串的这种长度的01串共有多少个, ...
- 【巧妙】【3-21个人赛】Problem C 01串
Problem C Time Limit : 3000/1000ms (Java/Other) Memory Limit : 65535/32768K (Java/Other) Total Sub ...
- NYOJ-252 01串
01串 时间限制:1000 ms | 内存限制:65535 KB 难度:2 描写叙述 ACM的zyc在研究01串,他知道某一01串的长度,但他想知道不含有"11"子串的这样的长 ...
- NYOJ 252 01串(斐波那契数列变形)
01串 时间限制:1000 ms | 内存限制:65535 KB 难度:2 描述 ACM的zyc在研究01串,他知道某一01串的长度,但他想知道不含有“11”子串的这种长度的01串共有多少个, ...
- 1415: 小ho的01串 [字符串]
点击打开链接 1415: 小ho的01串 [字符串] 题目描述 有一个由0和1组成的字符串,它好长呀--------一望无际 恩,说正题,小ho的数学不太好,虽然是学计算机的但是看见0和1也是很头疼的 ...
随机推荐
- js(四) 全选/全不选和反选
思路:通过选择全选的选框的状态stuts 即true/false控制其他选框. 首先 我们要通过.checked方法获取选框(全选/全不选)的值. function all(){ var stuts= ...
- Educational Codeforces Round 61
Educational Codeforces Round 61 今早刚刚说我适合打pikmike出的EDU 然后我就挂了 A 不管 B 不管 C 这道题到快结束了才调出来 大概就是\(n^2\)枚举不 ...
- 2018-10-23-WPF-使用-Pandoc-把-Markdown-转-Docx
title author date CreateTime categories WPF 使用 Pandoc 把 Markdown 转 Docx lindexi 2018-10-23 11:35:47 ...
- 【37.74%】【codeforces 725D】Contest Balloons
time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 计算机网络OSI模型
一. 理想模型-OSI 7层模型 那么数据是如何传输的呢?看下图:上层的Header+DATA作为新的Data再次被封装,到达目的地后就像剥洋葱一样掐头(去尾)最终留下你所要传的数据. 各层功能详细阐 ...
- WCF 服务应用程序
1. 创建 WCF 服务程序和客户端程序,参考如下: https://docs.microsoft.com/zh-cn/dotnet/framework/wcf/getting-started-tut ...
- .net webapi 文件夹上传
如果我是DJ,是DJ,是DJ,是DJ,是DJ,是DJ,是DJ,是DJ,是DJ,是DJ,,, 前言 文件夹上传目前仅支持chrome内核的浏览器. 后期整理到git(2019-5-23说:不整理了,我要 ...
- TCP/IP||UDP广播和多播
1.概述 广播和多播应用于UDP,TCP是一个面向连接协议,意味着分别运行与两个主机内的两进程间存在一个连接,在考虑多个主机内的共享通信网络,每个以太网帧包含源主机和目的主机以太网地址(48bit), ...
- poj - 3585(二次扫描与换根法)
周末牛客挂了个更难的,这个简单一些 #include<iostream> #include<cstring> #include<cstdio> #include&l ...
- 20191031-6beta week 1/2 Scrum立会报告+燃尽图 04
此作业要求参见https://edu.cnblogs.com/campus/nenu/2019fall/homework/9914 git地址:https://e.coding.net/Eustia/ ...