hihocoder#1410 : Powers of Two(水题)
来源:互联网 发布:淘宝pc端搭配套餐 编辑:程序博客网 时间:2024/06/06 09:18
时间限制:10000ms
单点时限:1000ms
内存限制:256MB
- 样例输入
7
- 样例输出
2
描述
Given a positive integer N, it is possible to represent N as the sum of several positive or negative powers of 2 (± 2k for some k). For example 7 can be represented as 22 + 21 + 20 and 23 + (-20).
Your task is to find the representation which contains the minimum powers of 2.
输入
One positive integer N.
For 80% of the data: 1 <= N <= 100000
For 100% of the data: 1 <= N <= 2000000000
输出
The minimum number of powers of 2.
#include<bits/stdc++.h>using namespace std;int f(long long n){ if(n==0)return 0; long long ans=1; while(ans*2<=n)ans*=2; ans=min(n-ans,2*ans-n); return 1+f(ans);}int main(){ long long n; scanf("%lld",&n); cout<<f(n)<<endl; return 0;}
阅读全文
1 0
- hihocoder#1410 : Powers of Two(水题)
- Libgdx powers of two
- CodeForces702B Powers of Two
- Ivan and Powers of Two
- Ivan and Powers of Two
- Ivan and Powers of Two
- Ivan and Powers of Two
- codeforces-Powers of Two(map的应用)
- Codeforces 702 B. Powers of Two(二分)
- CodeForces 702B Powers of Two(二分)
- 【CodeForces】702B - Powers of Two(二分)
- 【Codeforces】-702B-Powers of Two(二分)
- Educational Codeforces Round 15 B. Powers of Two (数学)
- CodeForces 702B: Powers of Two(遍历、穷举)
- CF_305_C. Ivan and Powers of Two
- Codeforces 702B - Powers of Two
- codeforces-702B-Powers of Two
- CodeForces 702B Powers of Two
- hdu 6005 Pandaland(dij+暴力)
- 爬虫学习笔记--Selenium PhantomJS
- json介绍
- Flume安装及简单部署
- Springboot打成war包并在tomcat中运行
- hihocoder#1410 : Powers of Two(水题)
- 浅谈vue 动态加载、注册组件
- Lucas–Kanade光流算法
- py2neo——Neo4j&python的配合使用
- mini-caffe编译,用BLVC caffe编译的mnist模型进行测试
- Java的设计模式之单例模式
- 二叉树之B树红黑树AVL树堆积树、B-树、B+总结分析
- 【Python-3.3】字典中存储字典
- mybatis