题目

https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2683

题意

原来有1个,每次可以任选数量成倍增长,问要操作多少次到n

思路

明显,先扩增到最大数位maxDigit,比如10,先扩增到8,然后再选择n - maxDigit扩增即可。因而结果为log2(n)

代码

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#define LOCAL_DEBUG
using namespace std;
typedef pair<int, int> MyPair; int cntDigit(int n) {
int ans = ;
int x = ;
while (n > x) {
ans++;
x <<= ;
}
return ans;
} int main() {
#ifdef LOCAL_DEBUG
freopen("C:\\Users\\Iris\\source\\repos\\ACM\\ACM\\input.txt", "r", stdin);
//freopen("C:\\Users\\Iris\\source\\repos\\ACM\\ACM\\output.txt", "w", stdout);
#endif // LOCAL_DEBUG
int n;
for (int ti = ; scanf("%d", &n) == && n > ; ti++) {
printf("Case %d: %d\n", ti, cntDigit(n));
} return ;
}

UVa 11636 - Hello World! 二分,水题 难度: 0的更多相关文章

  1. UVa 10340 - All in All 水题 难度: 0

    题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...

  2. UVa 3602 - DNA Consensus String 水题 难度: 0

    题目 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_pr ...

  3. UVa LA 3213 - Ancient Cipher 水题 难度: 0

    题目 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_pr ...

  4. UVa 10970 - Big Chocolate 水题 难度: 0

    题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...

  5. UVa 11636 Hello World! (水题思维)

    题意:给你一个数,让你求需要复制粘贴多少次才能达到这个数. 析:这真是一个水题,相当水,很容易知道每次都翻倍,只要大于等于给定的数就ok了. 代码如下: #include <iostream&g ...

  6. UVa 11039 - Building designing 贪心,水题 难度: 0

    题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...

  7. POJ 1840 Eqs 解方程式, 水题 难度:0

    题目 http://poj.org/problem?id=1840 题意 给 与数组a[5],其中-50<=a[i]<=50,0<=i<5,求有多少组不同的x[5],使得a[0 ...

  8. hdu 3687 10 杭州 现场 H - National Day Parade 水题 难度:0

    H - National Day Parade Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & % ...

  9. POJ 3126 Prime Path bfs, 水题 难度:0

    题目 http://poj.org/problem?id=3126 题意 多组数据,每组数据有一个起点四位数s, 要变为终点四位数e, 此处s和e都是大于1000的质数,现在要找一个最短的路径把s变为 ...

随机推荐

  1. Anroid 搭建Maven私服(Android Studio)

    一.场景 ① 公司中有多个项目,多人开发,开发中的某一模块需要被其他几个项目的模块所依赖,最简单粗暴的方式就是打包成aar或者jar文件逐个拷贝到libs下进行依赖,可是这种方式太过于麻烦,而且需要每 ...

  2. 如何选择合适的 DDoS 防御服务

    如果你没有对自己的站点采取一些必要的保护措施,将会使它直接暴露于 DDoS 攻击的风险下且无任何招架之力.你应该对法国大选日 knocked out 网站被 DDoS 攻击和 2016 年十月份时候美 ...

  3. leecode第一百二十二题(买卖股票的最佳时机II)

    class Solution { public: int maxProfit(vector<int>& prices) { int len=prices.size(); ) ; , ...

  4. Android JNI 传递对象

    JNI初步入门后,在传递数据的时候,遇到一个需求:有多个数据需要在Java与C代码之间进行传递.如果都做为函数参数传入,则函数很长很难看,并且多个数据的返回也不好实现.所以想到了把数据打包后传递.这在 ...

  5. Linux实际常用命令

    1.删除0字节文件 find -type f -size 0 -exec rm -rf {} \;  2.查看进程 按内存从大到小排列 ps -e -o “%C : %p : %z : %a”|sor ...

  6. Lua面向对象之一:简单例子

    1.Lua面向对象实现步骤 ①创建一个全局表(称之为元表) ②设置这个元表的__index值(值通常为元表自己,这样就能通过__index查找到对应的属性和方法) __index 赋值其实是一个fun ...

  7. 有效利用1 on 1

    2019-01-08 16:32:13 感觉1 on 1是浪费时间? 感觉1 on 1时没啥好说? 感觉老板总是不想1 on 1? 怎样才能 升职加薪? 一切都从有效的1 on 1开始!! 什么是1 ...

  8. Jumpserver3.0部署(Centos6.x)

    1.jumpserver基础环境准备[root@jumpserver ~]# yum -y install epel-release[root@jumpserver ~]# yum clean all ...

  9. Web版记账本开发记录(二)

    第二天又开始了,继续开始编辑之路. 今天在弄用户登录,也不知道为什么, 挺简单的一个程序耗时还挺多,在编程的过程中我发现昨天的思路有一些问题, 今天又重新理了一下思路. 还将昨天的表格给完善了一些,自 ...

  10. php中安装memcache

    1.查看php的版本(我的是5.6) 2.打开phpinfo查看第四行 3.然后选择要安装的文件 4.复制到 ext中 复制后 5.打开配置文件php.ini 把 extension=php_memc ...