题目链接:Tavas and SaDDas

Once again Tavas started eating coffee mix without water! Keione told him that it smells awful, but he didn't stop doing that. That's why Keione told his smart friend, SaDDas to punish him! SaDDas took Tavas' headphones and told him: "If you solve the following problem, I'll return it to you."

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 ≤ 10^9).

Output

Print the index of n among all lucky numbers.

题意描述:求出小于等于n并每一位上只包含4或7的数的个数。

算法分析:比赛的时候脑子大半夜短路了,刚开始一直在想枚举n的每个位上的数和4、7的关系,搞来搞去没出结果,后来才发现这样的数其实不多,每位上要求是4或7,一个数最多9位,也就2的9次方这么多呗,暴力求解然后判断这样的数和n的大小关系就OK了。

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#define inf 0x7fffffff
using namespace std;
const int maxn=; int n,m;
int an[][maxn]; int main()
{
while (scanf("%d",&n)!=EOF)
{
if (n<) {printf("0\n");continue; }
if (n>= && n<) {printf("1\n");continue; }
int cnt=;
memset(an,,sizeof(an));
an[][]= ;an[][]= ;
for (int i= ;i< ;i++)
{
int c=;
int t=,j=i-;
while (j) {t*=;j--; }
int flag=;
for (int j= ;j<=pow(,i-) ;j++)
{
an[i][c]=*t+an[i-][j];
if (an[i][c]>n) {flag=;break; }
cnt++;c++;
}
for (int j= ;j<=pow(,i-) ;j++)
{
an[i][c]=*t+an[i-][j];
if (an[i][c]>n) {flag=;break; }
cnt++;c++;
}
if (flag) break;
}
printf("%d\n",cnt);
}
return ;
}

Codeforces 535B Tavas and SaDDas 水题一枚的更多相关文章

  1. Codeforces Round #299 (Div. 2) B. Tavas and SaDDas 水题

    B. Tavas and SaDDas Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/535/p ...

  2. Codeforces B - Tavas and SaDDas

    535B - Tavas and SaDDas 方法一:打表大法. 代码1: #include<bits/stdc++.h> using namespace std; ]={,,,,,,, ...

  3. codeforces 577B B. Modulo Sum(水题)

    题目链接: B. Modulo Sum time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  4. Codeforces Round #367 (Div. 2)---水题 | dp | 01字典树

    A.Beru-taxi 水题:有一个人站在(sx,sy)的位置,有n辆出租车,正向这个人匀速赶来,每个出租车的位置是(xi, yi) 速度是 Vi;求人最少需要等的时间: 单间循环即可: #inclu ...

  5. codeforces 696A Lorenzo Von Matterhorn 水题

    这题一眼看就是水题,map随便计 然后我之所以发这个题解,是因为我用了log2()这个函数判断在哪一层 我只能说我真是太傻逼了,这个函数以前听人说有精度问题,还慢,为了图快用的,没想到被坑惨了,以后尽 ...

  6. CodeForces 589I Lottery (暴力,水题)

    题意:给定 n 和 k,然后是 n 个数,表示1-k的一个值,问你修改最少的数,使得所有的1-k的数目都等于n/k. 析:水题,只要用每个数减去n/k,然后取模,加起来除以2,就ok了. 代码如下: ...

  7. Codeforces Gym 100286G Giant Screen 水题

    Problem G.Giant ScreenTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/con ...

  8. codeforces 710A A. King Moves(水题)

    题目链接: A. King Moves 题意: 给出king的位置,问有几个可移动的位置; 思路: 水题,没有思路; AC代码: #include <iostream> #include ...

  9. codeforces 659A A. Round House(水题)

    题目链接: A. Round House time limit per test 1 second memory limit per test 256 megabytes input standard ...

随机推荐

  1. luogu3810 【模板】三维偏序(陌上花开)

    ref1 ref2 ref3 ref4 #include <algorithm> #include <iostream> #include <cstdio> usi ...

  2. 设计模式之第21章-状态模式(Java实现)

    设计模式之第21章-状态模式(Java实现) “what are you 干啥了?怎么这么萎靡不振?”“昨晚又是补新番,又是补小笼包,睡得有点晚啊.话说杨过的那个雕兄真是太好了,每天给找蛇胆,又陪练武 ...

  3. 【SCOI 2010】传送带

    为了方便,我们不妨设$\rm P \lt Q,R$ 我们发现,有$\rm E$点在$\rm AB$上,$\rm F$点在$\rm CD$上,最优解一定是$\rm AE\rightarrow EF\ri ...

  4. sql2005 和sql2008 同时安装

    Hkey_local_machine\Software\Wow6432Node\Microsoft\Microsoft SQL Server\90\Tools\ShellSEM 中的ShellSEM重 ...

  5. Android App程序结构

    先看结构图: ====================================== 1.   /src   源码目录,不解释. 2.  /gen   gen目录是ADT 自动生成的代码所在位置 ...

  6. [转]Pycharm 断点调试方法

    转自: https://blog.csdn.net/u013088062/article/details/50216015

  7. 用日志记录Linux用户执行的每一条命令(history)

    工作中,需要把用户执行的每一个命令都记录下来,并发送到日志服务器的需求,为此我做了一个简单的解决方案.这个方案会在每个用户退出登录 时把用户所执行的每一个命令都发送给日志守护进程rsyslogd,你也 ...

  8. iOS属性文字NSAttributedString

    它本身是一个Foundation框架的类, 但如果要使用它主要用到了UIKit框架中的NSAttributedString中的一些常量字符串 ----------------------------- ...

  9. HDU 4391 Paint The Wall(分块+延迟标记)

    Paint The Wall Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  10. POJ1848 Tree 【树形dp】

    题目链接 POJ1848 题解 由题,一个环至少由三个点组成,一个点作为根时,可以单独成链,可以与其一个儿子成链,或者与其两个儿子成环,与其一个剩余链长度大于等于2的儿子成环. 那么我们设最小代价 \ ...