题目

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. vue 父组件调用子组件方法

    情景: 父组件中引入上传附件的子组件:点击组件可以分别上传对应要求的图片,子组件内部循环可创建多个模块. 父组件传入数组子组件循环来创建不同的组件模块,所有事件都在子组件内部. 父组件页面的上方同时有 ...

  2. Codeforces 931F - Teodor is not a liar!

    931F - Teodor is not a liar! 思路: 最长上升子序列 先差分数组染色 如果存在一个点,被所有区间包含,那么这张图一定是山峰状,如下图: 那么只要分别从前和从后找一个最长非严 ...

  3. mui 访问系统相册将图片显示到网页

    访问系统相返回值为一个对象,通过转换为字符串可以查看,path.files[0]为返回路径去除路径赋值到src 调用摄像头返回的相片的path为一个路径通过 plus.io.resolveLocalF ...

  4. python相对目录的基本用法(一)

    一般在代码中涉及到操作文件时,最好使用文件的相对目录,这样在你的程序迁移到别人的电脑时,可以保证不会出现文件读取异常的错误(另外,自动化测试时用例的读取也要用相对目录) 例子1 假如工程文件的目录结构 ...

  5. 怎么从bam文件中提取出比对OR没比对上的paired reads | bamToFastq | STAR

    折腾这么多都是白瞎,STAR就有输出没有别对上的pair-end reads的功能 参见:How To Filter Mapped Reads With Samtools I had the same ...

  6. 安卓四大组件之Sevice组件的简单使用 --Android基础

    1.本例实现了简单的Service(服务)的创建.启动和停止,点击“启动SERVICE”页面会显示“服务被创建”,接着是“服务被启动”.点击“停止SERVICE”页面提示“服务被停止”.太过基础,直接 ...

  7. 使用getCurrentPosition方法实时获取当前Geolocation信息(附源码文件)--html5、JavaScript

    使用getCurrentPosition方法实时获取当前Geolocation信息: 1.getCurrentPosition方法的使用 navigator.geolocation.getCurren ...

  8. JavaScript的几个概念简单理解(深入解释见You Don't know JavaScript这本书)

    ES201X是JavaScript的一个版本. ES2015新的feature let, const Scope, 块作用域 Hoisting Closures DataStructures: Obj ...

  9. Confluence 6 对一个空间进行归档后产生的影响

    空间 如果一个空间被归档: 将不会在查找结果中显示,除非你选择 在归档空间中查找(Search archived spaces).如果没有归档空间的话,这个功能是隐藏的. 页面和内容将不会在 Conf ...

  10. Confluence 6 自定义空间布局

    你可以通过编辑布局文件来对 Confluence 的外观和表现进行编辑.这个页面将会告诉你如何来为空间自定义布局文件.你需要系统管理员的 全局权限(global permission) 和你希望进行修 ...