Codeforces-535B Tavas and SaDDas
来源:互联网 发布:北京办公软件速成班 编辑:程序博客网 时间:2024/06/10 07:34
The problem is:
You are given a lucky number n. Lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
If we sort all lucky numbers in increasing order, what’s the 1-based index of n?
Tavas is not as smart as SaDDas, so he asked you to do him a favor and solve this problem so he can have his headphones back.
Input
The first and only line of input contains a lucky number n (1 ≤ n ≤ 109).
Output
Print the index of n among all lucky numbers.
Example
Input
4
Output
1
Input
7
Output
2
Input
77
Output
6
分析:乍一看好像很复杂,其实就是一棵二分查找树。每次判断最高位的数字:4—-cnt=2*cnt+1;7—-cnt=2*cnt+2。
Source:
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespace std;int main(){ char s[15]; scanf("%s",s); int cnt=0; for(int i=0;i<strlen(s);i++) { if(s[i]=='4') cnt=2*cnt+1; else cnt=2*cnt+2; } printf("%d\n",cnt); return 0;}
- CodeForces 535B — Tavas and SaDDas
- codeforces 535B-Tavas and SaDDas
- Codeforces-535B Tavas and SaDDas
- 535B:Tavas and SaDDas
- B. Tavas and SaDDas
- B. Tavas and SaDDas
- coderforce 535B Tavas and SaDDas
- Codeforces Round #299 (Div. 2)B. Tavas and SaDDas
- Codeforces Round #299 (Div. 2)B. Tavas and SaDDas
- Code Forces 535 B. Tavas and SaDDas(数论)
- #299 (div.2) B. Tavas and SaDDas
- codeforces535B:Tavas and SaDDas
- cf. Tavas and SaDDas
- cf535B. Tavas and SaDDas
- [Codeforces 535B]Tavas and Karafs
- Codeforces 535C Tavas and Karafs(二分)
- Codeforces 535C Tavas and Karafs
- Codeforces 535C Tavas and Karafs(二分)
- tomcat 开启nio
- 初识StringBuffer类
- Vampire Numbers
- 设计模式拾荒之责任链模式 ( Chain of Responsibility)
- 搭建完全分布式Hadoop
- Codeforces-535B Tavas and SaDDas
- Vscode使用技巧
- effective C++ 使用条款(二)——item34~item46总结
- SQL injection(转载)+博主思考
- 第十一周
- Menu的详细使用
- java基础知识点,零碎点的整理篇
- Visual Studio 2017.4下载链接及密匙
- 深入理解Python(三)