Portal
A decimal integer is called the Power binary, when his decimal representation is made up of only 0 or 1. For example, 0,1,101,110011 are powerful binaries and 2,12,900 not.
When given an n, calculate the minimum number of powerful binary additions to get N.
Input
A single set of test data.
The first line gives an integer n (1<=n<=1,000,000)
Output
One row for the output answer.
Input example
9
Output example
9
Problem Solving Ideas:
This topic, in fact, the problem is to find the largest number of all digits, this is difficult to think of. As an example:
9998 can be obtained by 8 of 1111 and one 1110:
5656 can be obtained by 5 of 1111 and one 101
5678 can be obtained by 5 1111 and one 111 and one 11 and one 1
So it is to ask for a maximum value of 10 for each bit.
My Code:
#include <iostream> #include <cstdio> using Span class= "Hljs-keyword" >namespace STD ; int Main () {int N; scanf ( "%d" , &n); int ans = 0 ; while (n) {int m = N%10 ; if (Ans < m) ans = m; n/= 10 ; } cout <<ans<<endl; return 0 ;}
51NOD 1413 Powerful binary (thinking)