What is the meaning of C. Hexadecimal's Numbers?

2026-04-11 21:431阅读0评论SEO资源
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计542个文字,预计阅读时间需要3分钟。

What is the meaning of C. Hexadecimal's Numbers?

刚开始发现小于n+1位的二进制形式为2^n - 1,然后在剩余区间处理判断,发现TLE,于是只能好DFS。一个美好的七月早晨,在主框架中发生了一件可怕的事情:一个恶毒的病毒Megabyte不知为何成功入侵了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).

    What is the meaning of C. Hexadecimal's Numbers?

    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; }

本文共计542个文字,预计阅读时间需要3分钟。

What is the meaning of C. Hexadecimal's Numbers?

刚开始发现小于n+1位的二进制形式为2^n - 1,然后在剩余区间处理判断,发现TLE,于是只能好DFS。一个美好的七月早晨,在主框架中发生了一件可怕的事情:一个恶毒的病毒Megabyte不知为何成功入侵了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).

    What is the meaning of C. Hexadecimal's Numbers?

    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; }