cf535B. Tavas and SaDDas
2016-04-28 19:22
351 查看
B. Tavas and SaDDas
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
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 ≤ 109).
Output
Print the index of n among all lucky numbers.
Examples
input
output
input
output
input
output
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<queue>
#include<algorithm>
#include<list>
#include<cmath>
#include<vector>
using namespace std;
const int maxn=10010;
int num[2][maxn];
int Count(int n){
if(n==4)return 1;
if(n==7)return 2;
int ans=2,cnt=2;
int d=10,x=0;
num[0][1]=4;num[0][2]=7;
while(1){
int temp=0;
for(int i=1;i<=cnt;++i){
num[(x+1)%2][++temp]=num[x%2][i]+4*d;ans++;
if(num[(x+1)%2][temp]==n)return ans;
}
for(int i=1;i<=cnt;++i){
num[(x+1)%2][++temp]=num[x%2][i]+7*d;ans++;
if(num[(x+1)%2][temp]==n)return ans;
}
d*=10;cnt=temp;x++;
//break;
}
}
int main()
{
int n,i,j,k,l;
scanf("%d",&n);
printf("%d\n",Count(n));
return 0;
}
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
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 ≤ 109).
Output
Print the index of n among all lucky numbers.
Examples
input
4
output
1
input
7
output
2
input
77
output
6
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<queue>
#include<algorithm>
#include<list>
#include<cmath>
#include<vector>
using namespace std;
const int maxn=10010;
int num[2][maxn];
int Count(int n){
if(n==4)return 1;
if(n==7)return 2;
int ans=2,cnt=2;
int d=10,x=0;
num[0][1]=4;num[0][2]=7;
while(1){
int temp=0;
for(int i=1;i<=cnt;++i){
num[(x+1)%2][++temp]=num[x%2][i]+4*d;ans++;
if(num[(x+1)%2][temp]==n)return ans;
}
for(int i=1;i<=cnt;++i){
num[(x+1)%2][++temp]=num[x%2][i]+7*d;ans++;
if(num[(x+1)%2][temp]==n)return ans;
}
d*=10;cnt=temp;x++;
//break;
}
}
int main()
{
int n,i,j,k,l;
scanf("%d",&n);
printf("%d\n",Count(n));
return 0;
}
相关文章推荐
- 运维入门
- Varnish Install And Configure
- SQL Server 2005中更改sa的用户名的方法
- 在安装sql2005中或安装后sa用户无法登陆系统解决方法
- SA 沙盘模式下不用恢复xp_cmdshell和xplog70.dll也执行命令
- mssql SA帐号的改名和删除
- sql2005 sa执行命令方法总结
- SQL Server 2008用'sa'登录失败,启用'sa'登录的解决办法
- 解决SqlServer 各版本 sa帐户不能登录问题
- Insert Date and Time into Access
- asp的SQL语句中and和or同时使用的注意事项
- 拖动Html元素集合 Drag and Drop any item
- 学习drag and drop js实现代码经典之作
- And,Where使用提示以及用+进行左关联的提示及注意事项
- Android开发adb.exe' and can be executed.错误解决方法
- SQL2000中的默认sa帐号的修改与删除方法
- Table ‘xxx’ is marked as crashed and should be repaired 错误解决方法参考
- drag-and-drop实现图片浏览器预览
- python关键字and和or用法实例
- Python and、or以及and-or语法总结