UVa 11384 - Help is needed for Dexter 分析, 树状数组 难度: 0
题目
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2379
题意
[1, .., n],每次可以减一个1-n之间的数,问至少多少次能将全部数字减为0(减为0后不再变化)
思路
如刘书思路。
想到1...n,就会想到树状数组分bit存储的思想,进而就会觉得分bit减是一个想法。因为log2(n) <= (x - 1)logx(n), 此处x大于等于3,所以可以认为答案就是结果的bit长度。
感想
1. 三倍ice cream!
代码
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <tuple>
#include <set>
#include <map>
#include <cassert>
#define LOCAL_DEBUG
using namespace std; int mylog(int n) {
int x, bit;
x = ;
bit = ;
while (x <= n) {
x <<= ;
bit++;
}
return bit;
} int main() {
#ifdef LOCAL_DEBUG
freopen("input.txt", "r", stdin);
//freopen("output2.txt", "w", stdout);
#endif // LOCAL_DEBUG
int n;
for (int ti = ; scanf("%d", &n) == ; ti++) {
printf("%d\n", mylog(n));
} return ;
}
UVa 11384 - Help is needed for Dexter 分析, 树状数组 难度: 0的更多相关文章
- UVA.11384 Help is needed for Dexter (思维题)
UVA.11384 Help is needed for Dexter (思维题) 题意分析 同样水题一道,这回思路对了. 给出数字n,面对一个1,2,3,4--n的数字序列,你可以对他们的部分或者全 ...
- UVA 11384 Help is needed for Dexter(问题转化 递归)
Help is needed for Dexter Time Limit: 3 Second Dexter is tired of Dee Dee. So he decided to keep Dee ...
- UVa 11384 Help is needed for Dexter
分析题目以后得出,对于一个连续等差递增的序列,例如1,2,3,4,5,6,每次选择其中后一半,减去能减的最大数,则是最优操作. 上述序列经过一次操作后变为1,2,3,0,1,2,此时可抛弃后一半(已经 ...
- UVa 11384 Help is needed for Dexter 正整数序列
给定一个正整数 n ,你的任务使用最少的操作次数把序列 1, 2, 3, -- , n 中的所有数都变成 0 .每次操作可以从序列中选择一个或者多个数,同时减去一个相同的正整数.比如,1, 2, 3 ...
- UVA 11384 Help is needed for Dexter(递归)
题目链接:https://vjudge.net/problem/UVA-11384 这道题要分析得透: 如果我们手模的话,会发现:如果先将大于$\frac{n}{2}$的数都减去$\frac{n}{2 ...
- UVa 11384 Help is needed for Dexter (递归)
题意:给定一个n表示1到n的序列,让你用最小的步数把这个序列都变为0,每个操作可以从序列中选择一个或多个个,同时减掉一个正整数,求最少的步数. 析:一看这个题,感觉挺高深的,但是静下心来想想,其实挺简 ...
- UVA 12446 How Many... in 3D! ( 递推 + 树状数组 )
C. How Many... in 3D! Time Limit: 1000ms Memory Limit: 131072KB 64-bit integer IO format: %lld ...
- UVA 1513 - Movie collection(树状数组)
UVA 1513 - Movie collection option=com_onlinejudge&Itemid=8&page=show_problem&category=5 ...
- UVA 11990 `Dynamic'' Inversion CDQ分治, 归并排序, 树状数组, 尺取法, 三偏序统计 难度: 2
题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...
随机推荐
- (转)winform之RichTextBox
RichTextBox是一种可用于显示.输入和操作格式文本,除了可以实现TextBox的所有功能,还能提供富文本的显示功能. 控件除具有TextBox 控件的所有功能外,还能设定文字颜色.字体和段落格 ...
- English trip M1 - AC11 May I Help You? 我能帮到你吗? Teacher:Lamb
In this lesson you will learn to ask for things in shops 在本课程中,您将学习如何在商店中寻找东西 课上内容(Lesson) How are ...
- Shell Trap信号管理
trap命令用于指定在接收到信号后将要采取的动作.常见的用途是在脚本程序被中断时完成清理工作.不过,这次我遇到它,是因为客户有个需求:从终端访问服务器的用户,其登陆服务器后会自动运行某个命令,例如打开 ...
- LeetCode--400--第N个数字
问题描述: 在无限的整数序列 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ...中找到第 n 个数字. 注意: n 是正数且在32为整形范围内 ( n < 231). ...
- yarn hadoop-2.3.0 installation cluster Centos 64bits
Apache Hadoop -2.2.0 - How to Install a Three Nodes Cluster http://tonylixu.blogspot.ca/2014/02/apac ...
- IntelliJ IDEA 第一个 Scala 程序
IntelliJ 安装完成 Scala 插件后,你需要尝试使用 IntelliJ 来创建并且运行第一个程序. 通常这个程序只是简单的输出 Hello World. 创建一个新工程 在文件下面选择新建, ...
- PHP const关键字
常量是一个简单的标识符.在脚本执行期间该值不能改变(除了所谓的魔术常量,他们其实不是常量).常量默认大小写敏感.通常常量标识符总是大写的. 可以用define()函数来定义常量.在php5.3.0以后 ...
- vi常用快捷键
vi常用快捷键 1)移动光标 h :光标左移一个字符k :光标上移一个字符j :光标下移一个字符l :光标右移一个字符 0 :光标移至行首$ :光标移至行尾 H :光标移至屏幕首行M :光标移至屏幕中 ...
- 正睿 2018 提高组十连测 Day2 T2 B
题目链接 http://www.zhengruioi.com/contest/84/problem/318 题解写的比较清楚,直接扒过来了. B 算法 1 直接按题意枚举,动态规划或是记忆化搜索. 时 ...
- spring boot 2.0(一)权威发布spring boot2.0
Spring Boot2.0.0.RELEASE正式发布,在发布Spring Boot2.0的时候还出现一个小插曲,将Spring Boot2.0同步到Maven仓库的时候出现了错误,然后Spring ...