题目链接: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. 46、android studio第一次使用时卡在gradle下载怎么解决?

    如果没法FQ或者FQ后网速慢,哥教你一个快速解决方案. 在根目录下的.gradle目录下,找到wrapper/dists目录,如果当前正在下载gradle.x.xx-all.zip,那么会发现grad ...

  2. ios开发学习笔记040-autolayout 第三方框架Masonry

    不管是是界面创建约束还是代码创建约束,苹果官方提供的方式都比较繁琐.所以出现了第三方框架. Masonry 在github地址如下: https://github.com/SnapKit/Masonr ...

  3. aircrack-ng破解wlan无线流量包

    记录一下新的知识点. 无线协议里最关键的就是EAPOL协议了,这个里面保存着密钥,所以破解无线流量包也应该从这里入手. 用到的工具是aircrack-ng,这个在kali自带,也可以下载windows ...

  4. MOTCF 没时间解释了 条件竞争漏洞

    moctf 没时间解释了 条件竞争漏洞 题目链接 条件竞争: 在本题目中,上传文件的时候服务器无条件的接收任何类型的文件,但是你上传之后服务器会给你的文件内容修改为too slow. 比如你上传了一句 ...

  5. 理解机器为什么可以学习(三)---Theory of Generalization

    前边讨论了我们介绍了成长函数和break point,现在继续讨论m是否成长很慢,是否能够取代M. 成长函数就是二分类的排列组合的数量.break point是第一个不能shatter(覆盖所有情形) ...

  6. C# 泛型的入门理解(来自网络)

    using System.Collections; class Program { //做个比较 static void Main(string[] args) { //new对象 Cls a1 = ...

  7. libcmt.lib和msvcrt.lib冲突,原因和解决方法

    libcmt.lib和msvcrt.lib冲突,原因和解决方法 https://blog.csdn.net/longlijun/article/details/7331093 libcmt.lib是w ...

  8. aplusb 数论

    题目描述 SillyHook 要给小朋友出题了,他想,对于初学者,第一题肯定是a+b啊, 但当他出完数据后神奇地发现.in 不见了,只留下了一些.out,他想还原.in,但 情况实在太多了,于是他想要 ...

  9. 运输问题2(cogs 12)

    [问题描述]     一个工厂每天生产若干商品,需运输到销售部门进行销售.从产地到销地要经过某些城镇,有不同的路线可以行走,每条两城镇间的公路都有一定的流量限制.为了保证公路的运营效率,每条公路都有一 ...

  10. Codeforces Round #398 (Div. 2) A-E

    分数史上新低 开场5分钟过了A题,想着这次赌一把手速,先去切C吧 看完C题觉得这应该是道水题,码了十分钟提交,WA 想着这明明是道水题,估计少考虑了情况,添了几行再交,WA 不可能啊,这题都A不掉,和 ...