当前位置:网站首页>51nod 1413 权势二进制
51nod 1413 权势二进制
2022-07-15 11:44:00 【51CTO】
一个十进制整数被叫做权势二进制,当他的十进制表示的时候只由0或1组成。例如0,1,101,110011都是权势二进制而2,12,900不是。
当给定一个n的时候,计算一下最少要多少个权势二进制相加才能得到n。
Input
单组测试数据。 第一行给出一个整数n (1<=n<=1,000,000)
Output
输出答案占一行。
Input示例
9
Output示例
9
一开始做这个我掏出了祖传的DFS,但并没有写出来。
然后观察数据,发现可以将所给的n的每一位都拿出来,然后找一个跟n一样长的权势二进制数,n的每一位如果大于1,这个二进制数的那一位就等于1,否则等于0,然后这个数绝对是能以最小加到n的,然后n减去这个数,再重复这些步骤,就能算出来了。
代码如下:
边栏推荐
- 2022-04-18 C Part 4 - Advanced
- 在 CDP中使用Iceberg 为数据湖仓增压
- Vector
- 05 USART sending and receiving data (query mode)
- Practice of kotlin stateflow search function DB + network
- A --- DMA serial port communication
- 实现意识的远程直接电磁通信,东大团队联合新加坡国大等构建电磁脑机超表面,有望成为全新通信范式
- 【综合笔试题】难度 2/5,递归运用及前缀和优化
- 送你的代码上太空,与华为云一起开发'最伟大的作品'
- What is kotlin sealed? Why does Google use it all
猜你喜欢

Solve the problem of installing Oracle /usr/bin/ld: cannot find -lclntshcore

2022-04-20 unity entry 6 - light source components

08 使用定时器控制LED闪烁

1、OLED简单驱动
![[recruitment] 2022 Xiangguang award annual ESG influence investment award is officially launched!](/img/11/64ad076cee870bd1aa42a6691ad841.jpg)
[recruitment] 2022 Xiangguang award annual ESG influence investment award is officially launched!

送你的代碼上太空,與華為雲一起開發'最偉大的作品'

Yunna dynamic loop monitoring system realizes unmanned rapid fault handling

在 PostgreSQL 15 上使用 postgres_fdw 进行事务的并行提交

Svn download and Chinese package installation

pygame游戏——飞机大战(待完善)
随机推荐
活动预告|Apache Doris x Apache SeaTunnel 联合 Meetup 开启报名!
03 key control LED
2022-04-18 C Part 4 - Advanced
MQTT---CONNECT连接
BC20 AT指令测试
女生学编程为什么难?是思维方式不对还是学习方式不对?
Xu Shiwei: the road of go+ evolution
Nacos as the registration and discovery center and configuration center of microservice architecture
pygame快速入门
08 使用定时器控制LED闪烁
竟然如此简单,DataBinding 和 ViewBinding
Xpath实战之爬取学习猿地的猿著(下)
[google] goodbye SharedPreferences embrace jetpack datastore
It should be so simple. Databinding and viewbinding
03 按键控制LED
Vector
2022-04-19 unity getting started 4 - important components and APIs
Svn download and Chinese package installation
【毕设选题】基于STM32的毕业设计题目项目汇总 - 350例
缓存雪崩、缓存击穿、缓存穿透