UVa 11636 - Hello World! 二分,水题 难度: 0
题目
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的更多相关文章
- UVa 10340 - All in All 水题 难度: 0
题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...
- UVa 3602 - DNA Consensus String 水题 难度: 0
题目 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_pr ...
- UVa LA 3213 - Ancient Cipher 水题 难度: 0
题目 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_pr ...
- UVa 10970 - Big Chocolate 水题 难度: 0
题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...
- UVa 11636 Hello World! (水题思维)
题意:给你一个数,让你求需要复制粘贴多少次才能达到这个数. 析:这真是一个水题,相当水,很容易知道每次都翻倍,只要大于等于给定的数就ok了. 代码如下: #include <iostream&g ...
- UVa 11039 - Building designing 贪心,水题 难度: 0
题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...
- POJ 1840 Eqs 解方程式, 水题 难度:0
题目 http://poj.org/problem?id=1840 题意 给 与数组a[5],其中-50<=a[i]<=50,0<=i<5,求有多少组不同的x[5],使得a[0 ...
- hdu 3687 10 杭州 现场 H - National Day Parade 水题 难度:0
H - National Day Parade Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & % ...
- POJ 3126 Prime Path bfs, 水题 难度:0
题目 http://poj.org/problem?id=3126 题意 多组数据,每组数据有一个起点四位数s, 要变为终点四位数e, 此处s和e都是大于1000的质数,现在要找一个最短的路径把s变为 ...
随机推荐
- 基于Arcface 免费离线人脸识别 2.0 Demo C#
本来打算做个C#版demo,但没用成功.使用虹软最新人脸识别技术开发完成 过程如下: 1. 传入一张单人脸照片: 2.调用检测人脸函数ASFDetectFaces,成功返回人脸信息的指针: 3.使用 ...
- Codeforces 985 D - Sand Fortress
D - Sand Fortress 思路: 二分 有以下两种构造, 分别二分取个最小. 代码: #include<bits/stdc++.h> using namespace std; # ...
- git Bash下复制粘贴
git复制:Ctrl+insert git粘贴:Shift+Insert git常用快捷键链接地址:https://www.jianshu.com/p/cc1fbd89e087 在gitHup上下载他 ...
- C# : 泛型的继承关系实现的一个可以存放不同数据类型的链表
以下定义的是一个链表结点类型: internal sealed class Node<T> { public T m_data; public Node<T> m_next; ...
- 第 3 章 镜像 - 016 - Dockerfile 常用指令
Dockerfile 常用指令 1.FROM 指定base镜像2.MAINTAINER 设置镜像的作者,可以为任意字符串3.COPY 从build context 复制到镜像 COPY 支持两种形式: ...
- 最简单的解决Chrome浏览器主页被hao123、360和2345篡改的方法是什么
最简单的解决Chrome浏览器主页被hao123.360和2345篡改的方法是什么 一.总结 一句话总结:打开chrome的安装目录,将chrome.exe改成chrome1.exe即可,然后发送一个 ...
- springboot---->获取不到yml配置文件指定的值
import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.Spr ...
- 扩大了一个逻辑卷,resize2fs 保错:没有这个超级块
检查发现,文件系统类型是xfs,应该使用 xfs_growfs命令刷新文件系统
- python记录_day22 序列化
序列化是指把内存里的数据类型转换成字符串,以使其能存储到硬盘或通过网络传输到远程,因为硬盘和网络传输时只能接受bytes 一.pickle 把python对象写入到文件中的一种解决方案,但是写入到文件 ...
- sqlserver给指定用户授权访问指定表
一. 背景 外部公司的人授权访问我们公司的数据库,数据接口调用,要给他们建立查看指定的视图和授权的账号,因此要在数据库中,给指定用户授权访问指定表 二.sqlserver 脚本 ---创建视图CR ...