权势二进制(51Nod-1413)
生活随笔
收集整理的這篇文章主要介紹了
权势二进制(51Nod-1413)
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
題目
一個(gè)十進(jìn)制整數(shù)被叫做權(quán)勢二進(jìn)制,當(dāng)他的十進(jìn)制表示的時(shí)候只由0或1組成。例如0,1,101,110011都是權(quán)勢二進(jìn)制而2,12,900不是。
當(dāng)給定一個(gè)n的時(shí)候,計(jì)算一下最少要多少個(gè)權(quán)勢二進(jìn)制相加才能得到n。
輸入
單組測試數(shù)據(jù)。
第一行給出一個(gè)整數(shù)n (1<=n<=1,000,000)
輸出
輸出答案占一行。
輸入樣例
9
輸出樣例
9
思路:分解每一位然后累計(jì),暴力即可
源程序
#include<iostream> #include<cstdio> #include<cstdlib> #include<string> #include<cstring> #include<cmath> #include<ctime> #include<algorithm> #include<utility> #include<stack> #include<queue> #include<vector> #include<set> #include<map> #define EPS 1e-9 #define PI acos(-1.0) #define INF 0x3f3f3f3f #define LL long long const int MOD = 1E9+7; const int N = 1000000+5; const int dx[] = {-1,1,0,0}; const int dy[] = {0,0,-1,1}; using namespace std;int main() {LL n;scanf("%lld",&n);LL maxx=-INF;while(n) {maxx=max(maxx,n%10);n/=10;}printf("%d\n",maxx);return 0; }總結(jié)
以上是生活随笔為你收集整理的权势二进制(51Nod-1413)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 组合数学 —— 概述
- 下一篇: 愤怒的牛(信息学奥赛一本通-T1433)