题目链接: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. Error:Execution failed for task ':myapplication:processDebugResources'. > com.android.ide.common.pro

    Error:Execution failed for task ':myapplication:processDebugResources'. > com.android.ide.common. ...

  2. 小米r3g旧版开发版固件,安装opkg

    1.开启ssh 1.1.刷入固件 在路由器更新界面,刷入 miwifi_r3g_firmware_c2175_2.25.122.bin 固件 下载地址: http://bigota.miwifi.co ...

  3. 洛谷P1067 多项式输出

    题目链接:https://www.luogu.org/problemnew/show/P1067 这是一个纯模拟的小怪但是需要注意一些小细节: 1.首项为正没有+号. 2.所有项系数如果是一的话就省略 ...

  4. 56、使用android studio(v1.3.*)修改包名 (rename package name)

    一.修改包名 ①选中目录,开始构造 在弹窗中选中Rename directory 在弹窗中选中Rename package 填写新的包名,点击Refactor 如果有警告,不用管它,直接点击Do Re ...

  5. leetcode 【 Trapping Rain Water 】python 实现

    题目: Given n non-negative integers representing an elevation map where the width of each bar is 1, co ...

  6. loadrunner11使用wplus_init_wsock录制非IE脚本/手机抓包

    假如你的IE版本号太高,或者是chrome,firfox,又或者想录手机上的包,可以用loadrunner的wplus_init_wsock工具   1.在创建LR脚本的Start Recording ...

  7. jQuery操作DOM基础 - 元素属性的查看与设置

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  8. BZOJ4650 [NOI2016]优秀的拆分 【后缀数组】

    题目 如果一个字符串可以被拆分为 AABBAABB 的形式,其中 AA 和 BB 是任意非空字符串,则我们称该字符串的这种拆 分是优秀的.例如,对于字符串 aabaabaa,如果令 A=aabA=aa ...

  9. bzoj1902【Zju2116】 Christopher

    题意:http://www.lydsy.com/JudgeOnline/problem.php?id=1902 sol  :一眼可以看出此题应用了lucas定理(逃~ 将n,m都化为p进制,记为a[] ...

  10. cmake 版本升级

    1.在网址 https://cmake.org/files/v3.1/下载   cmake-3.1.0.tar.gz 2.解压 3.执行  ./configure 4.执行 make 5. 执行   ...