题目链接: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. TCP/IP网络编程之多进程服务端(一)

    进程概念及应用 我们知道,监听套接字会有一个等待队列,里面存放着不同客户端的连接请求,如果有一百个客户端,每个客户端的请求处理是0.5s,第一个客户端当然不会不满,但第一百个客户端就会有相当大的意见了 ...

  2. 【palindrome partitioning II】cpp

    题目: Given a string s, partition s such that every substring of the partition is a palindrome. Return ...

  3. IOS开发学习笔记027-UITableView 使用模型对象

    1.模型对象 2.单组数据的显示 1.模型对象 继续优化上一个程序 上一次用到字典,但是坏处多多.这里将这些数据封装到类中. 这就是MVC中得模型,模型就是数据的显示结构 新建一个类,添加几个属性和一 ...

  4. IOS开发学习笔记006 - 指针

    C语言 指针 简单使用如下: int *p;//定义 int a = 10; p = &a;//赋值 int * b = &a;//定义并赋值 定义格式:类型 *指针变量名: 注意事项 ...

  5. docker exec小脚本

    经常要使用docker exec -it containerID bash 进入docker内部进行一些操作,干脆把它写成shell脚本节省时间. # 查看需要操作的容器id $ docker ps ...

  6. redis linux 安装

    安装 1): wget http://download.redis.io/releases/redis-5.0.2.tar.gz 2): tar xzf redis-5.0.2.tar.gz 3):c ...

  7. [SDOI2011][bzoj2286] 消耗战 [虚树+dp]

    题面: 传送门 思路: 看到所有询问中的点数总和是十万级别的,就想到用虚树~\(≧▽≦)/~啦 首先,树形dp应该是很明显可以看出来的: 设dp[u]表示以u为根的子树(不包括u)中的宝藏岛全部切断的 ...

  8. [ACG001E] BBQ hard [dp]

    题面: 传送门 思路: 首先,一个暴力的想法 对于每一对pack,求出f(ai+aj,bi+bj),其中f(x,y)=(x+y)!/(x!y!),也就是x个a,y个b的排列方式个数 然后转化模型,将f ...

  9. Linux系统——常见的系统调用

    本文列出了大部分常见的Linux系统调用,并附有简要中文说明. 以下是Linux系统调用的一个列表,包含了大部分常用系统调用和由系统调用派生出的的函数.这可能是你在互联网上所能看到的唯一一篇中文注释的 ...

  10. python和tensorflow安装

    一.Python安装 python采用anaconda安装,简单方便,下载python3.6的anaconda  linux64的sh安装文件. 1.bash Anaconda-2.1.0-Linux ...