当前位置 : 主页 > 编程语言 > c语言 >

C. Hexadecimal's Numbers

来源:互联网 收集:自由互联 发布时间:2023-09-07
刚开始发现小于 n 位的二级制形式数为 2^n-1 个,然后再在剩下的区间处理判断,发现TLE ,于是只好 DFS。 One beautiful July morning a terrible thing happened in Mainframe: a mean virus Megabyte somehow got ac
  • 刚开始发现小于 n 位的二级制形式数为 2^n-1 个,然后再在剩下的区间处理判断,发现TLE ,于是只好 DFS。
  • One beautiful July morning a terrible thing happened in Mainframe: a mean virus Megabyte somehow got access to the memory of his not less mean sister Hexadecimal. He loaded there a huge amount of n different natural numbers from 1 to n to obtain total control over her energy.

    But his plan failed. The reason for this was very simple: Hexadecimal didn't perceive any information, apart from numbers written in binary format. This means that if a number in a decimal representation contained characters apart from 0 and 1, it was not stored in the memory. Now Megabyte wants to know, how many numbers were loaded successfully.

    Input

    Input data contains the only number n (1 ≤ n ≤ 109).

    Output

    Output the only number — answer to the problem.

    Examples input Copy 10 output Copy 2 Note

    For n = 10 the answer includes numbers 1 and 10.


#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
#define maxn 2000005
#define inf 0x3f3f3f3f
#define ii 0x3f
const int mod = 1e9 + 7;
// dp[i]=min(dp[j]+(i-j-1+sum[i]-sum[j]-l)^2)
//  dp[i] 表示前 i 个玩具装箱的费用
//  f[i]=sum[i]+i;
// c=1+l;
// f[i] 单增  

ll read() {
	ll x = 0, f = 1;
	char ch = getchar();
	while (ch < '0' || ch > '9') {
		if (ch == '-') {
			f = -1;

		}
		ch = getchar();
	}
	while (ch >= '0'&&ch <= '9') {
		x = x * 10 + ch - '0';
		ch = getchar();
	}
	return x * f;
}

ll quickpow(ll a, ll b) {
	ll ans = 1;
	while (b > 0) {
		if (b % 2)ans = ans * a;
		b = b / 2;
		a = a * a;
	}
	return ans;
}
//char s[maxn];

int ans;
ll n;
void dfs(ll x) {
	if (x > n)return;
	ans++;
	dfs(x * 10);
	dfs(x * 10 + 1);

}

int main() {
	ios::sync_with_stdio(false);
	//ll n;
	cin >> n;
	ans = 0;
	dfs(1);
	cout << ans << endl;
}

上一篇:最小生成树模板
下一篇:没有了
网友评论