题目

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. leecode第六十一题(旋转链表)

    /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode ...

  2. cocos2dx spine之一 :spine缓存 (c++ & lua)

    cocos2dx版本为3.10 1.在使用spine的过程中,发现了一个比较严重的问题:每次创建SkeletonAnimation的时候都会很卡,即使是使用同一个骨骼数据skeletonData. 跟 ...

  3. Ubuntu 16 , 从时间服务器更新时间

    因为在公司的内网,所以不能用Ubuntu默认的服务器去更新时间. 只能改成从网关 10.182.202.2 上取时间 1) 如果没有安装ntp 的话,先安装 apt-get install ntp 2 ...

  4. FireFox(火狐)浏览器的相关问题

    如何加快FireFox(火狐)浏览器浏览网页速度 大部分网页加载缓慢的原因:1.宽带连接.网速不稳定2.浏览器本身问题,如果多开窗口浏览会占大量内存,而且磁盘空间没有做过优化,就这样电脑资源不够用,也 ...

  5. 提取出一个组装基因组的gap(N)和重复序列区域,保存为bed格式

    参见: Question: How to extract allnon-seqencedpositions from a genome (Fasta file)? test.fa >chr1 N ...

  6. 关于Mysql 查询所有表的实时记录用于对比2个MySQL 库的数据是否异步

    Xu言: 今天,为了研究一个MySQL主从同步开机后报错 问题,如下图 故障原因分析: 经过分析,可能是主从服务器开机顺序导致.(有待下次断电再次测试) 主从错误提示:日志读取错误的问题.解决方法:更 ...

  7. English trip M1 - AC11 I Dreamed a Dream? 我做了一个梦 Teacher:Lamb

    In this lesson you will learn to describe an experience.  这节课你讲学习到描述经历 课上内容(Lesson) 词汇(Key Word ) 句型 ...

  8. numpy---one

    import numpy as np #创建数组(给array函数传递Python序列对象) a = np.array([1,2,3,4,5]) b = np.array((1,2,3,4,5,6)) ...

  9. vue.js面试题整理

    Vue.js面试题整理 一.什么是MVVM? MVVM是Model-View-ViewModel的缩写.MVVM是一种设计思想.Model 层代表数据模型,也可以在Model中定义数据修改和操作的业务 ...

  10. python记录_day27 tcp/ip五层模型

    ## 网络协议按照不同的功能分为多层,目前存在的模型有osi七层模型.tcp/ip五层和tcp/ip四层模型 我们主要用的是tcp/ip五层模型 那么每层的作用是什么呢,现在就从设计者的角度自下到上逐 ...