题目

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. 基于虹软 2.0 人脸识别猜年龄 java版 demo

    首先感谢虹软,是你们提供这么好的SDK支撑了我们的想象力! 这是一个用javav编写的可视化应用,用户通过自己的脸和计算机进行交互,计算机则通过萌萌女孩的语音和用户对话.核心程序就是利用ArcFace ...

  2. docker下debian镜像开启ssh, 允许root用密码登录

    用的官方python镜像做开发, 暴露端口, 用pycharm ssh进去开发. 忽然发现本来ssh能连上, 但是更了新的python镜像连不上了. 有折腾了一下, 连上了. 主要是python官网镜 ...

  3. 解码字符串 Decode String

    2018-11-14 17:56:12 问题描述: 问题求解: 方法一.递归求解 最直观的解法就是递归来求了,并且很显然的这个问题可以使用递归来进行求解. public String decodeSt ...

  4. boke练习: category类的编辑修改,总是提示:该分类名称已经存在

    boke练习: category类的编辑修改,总是提示:该分类名称已经存在 本利采用的dao是: jpaRepository方式 先看原始代码: category的实体类 @Entity public ...

  5. datagrid复制

    private void Dgv_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == (char)1) // Ctrl-A ...

  6. English trip V1 - B 17. Giving Information 提供信息 Teacher:Taylor Key: Person Information

    In this lesson you will learn to say your phone number and address.  这节课讲学习说你的手机号码和地址. 课上内容(Lesson) ...

  7. p1217 Prime Palindromes

    1.回文质数的数量很少 2.除了11以外的回文质数都是偶数. 3.1-1亿内的回文数不到30000个. 4.1-10000的质数约1000个. 这样深搜找出所有的回文数,再判断是否质数. #inclu ...

  8. find_first_zero_bit在使用gcc 4.2.4 编译时,需要保护%eax

    1.3.100 find_first_zero_bit在使用gcc 4.2.4 编译时,需要保护%eax find_first_zero_bit 修订后: /* * Find-bit routines ...

  9. deepin系统安装成功了之后重启电脑没有deepin启动选项的简单解决办法

    开机 连续按 f10(我的电脑是惠普的,由于主板的不同可能启动键也有所不同)进入 bios 界面如图 选择系统设置,启动选项  之后如图 选择 uefi  模式下的开机顺序栏的  操作系统管理员选项并 ...

  10. Spring Boot 是什么?

    Spring Boot 2.0 的推出又激起了一阵学习 Spring Boot 热,那么, Spring Boot 诞生的背景是什么?Spring 企业又是基于什么样的考虑创建 Spring Boot ...