题目

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的更多相关文章

  1. UVA.11384 Help is needed for Dexter (思维题)

    UVA.11384 Help is needed for Dexter (思维题) 题意分析 同样水题一道,这回思路对了. 给出数字n,面对一个1,2,3,4--n的数字序列,你可以对他们的部分或者全 ...

  2. 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 ...

  3. UVa 11384 Help is needed for Dexter

    分析题目以后得出,对于一个连续等差递增的序列,例如1,2,3,4,5,6,每次选择其中后一半,减去能减的最大数,则是最优操作. 上述序列经过一次操作后变为1,2,3,0,1,2,此时可抛弃后一半(已经 ...

  4. UVa 11384 Help is needed for Dexter 正整数序列

    给定一个正整数 n ,你的任务使用最少的操作次数把序列 1, 2, 3, -- , n 中的所有数都变成 0 .每次操作可以从序列中选择一个或者多个数,同时减去一个相同的正整数.比如,1, 2, 3 ...

  5. UVA 11384 Help is needed for Dexter(递归)

    题目链接:https://vjudge.net/problem/UVA-11384 这道题要分析得透: 如果我们手模的话,会发现:如果先将大于$\frac{n}{2}$的数都减去$\frac{n}{2 ...

  6. UVa 11384 Help is needed for Dexter (递归)

    题意:给定一个n表示1到n的序列,让你用最小的步数把这个序列都变为0,每个操作可以从序列中选择一个或多个个,同时减掉一个正整数,求最少的步数. 析:一看这个题,感觉挺高深的,但是静下心来想想,其实挺简 ...

  7. UVA 12446 How Many... in 3D! ( 递推 + 树状数组 )

    C. How Many... in 3D! Time Limit: 1000ms Memory Limit: 131072KB 64-bit integer IO format: %lld      ...

  8. UVA 1513 - Movie collection(树状数组)

    UVA 1513 - Movie collection option=com_onlinejudge&Itemid=8&page=show_problem&category=5 ...

  9. UVA 11990 `Dynamic'' Inversion CDQ分治, 归并排序, 树状数组, 尺取法, 三偏序统计 难度: 2

    题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...

随机推荐

  1. 了解java中垃圾回收机制

    Java的垃圾回收机制是Java环境自带有的,它不像c语言的malloc申请空间后需要Free()函数来释放,而Java中的代码块中所申请的空间可在程序执行完成后自动释放,但是是有局限性的,代码块所占 ...

  2. 02-python-垃圾回收机制

    转载自 https://www.cnblogs.com/Xjng/p/5128269.html 加以整理,方便记忆 1垃圾回收机制 Python中的垃圾回收是以引用计数为主,分代收集为辅.引用计数的缺 ...

  3. Spring Boot的@SpringBootApplication无法引入的问题

    转自:https://blog.csdn.net/cckevincyh/article/details/78962002 今天搭建了springboot,一开始遇到了一个问题,在自己创建的HelloA ...

  4. 单细胞文献分析 Quantitative single-cell rna-seq with unique molecular identifers

    Quantitative single-cell rna-seq with unique molecular identifers 这篇文章论证了 scRNA-seq 使用UMI来计算基因表达量的合理 ...

  5. Zabbix安装(debian,centos)

    lnmp和lamp架构搭建一键安装脚本下载地址:https://lnmp.org/download.html  https://github.com/teddysun/lamp/tree/master ...

  6. .net WinForm 的数据绑定

    .net WinForm 的数据绑定相当灵活 http://www.cnblogs.com/ydong/archive/2006/04/22/381847.html 原来只知道 Control 类上的 ...

  7. mysql存储引擎的对比

  8. 关于js原型链

    关于原型链,我们先贴上一张图(来自某知乎大佬专栏),然后听我娓娓道来. 先来说说什么是原型? JavaScript 中的对象有一个特殊的 [[Prototype]] 内置属性,其实就是对于其他对象的引 ...

  9. vue嵌套路由--params传递参数

    在嵌套路由中,父路由向子路由传值除了query外,还有params,params传值有两种情况,一种是值在url中显示,另一种是值不显示在url中. 1.显示在url中index.html <d ...

  10. flask-前台布局页面搭建3

    4.前台布局的搭建 由于前端知识有限,我在网上下载的人家的前台源码,附上链接 https://link.jianshu.com/?t=https://github.com/mtianyan/movie ...