题目链接

https://vjudge.net/problem/26096/origin

题目

Dexter is tired of Dee Dee. So he decided to keep Dee Dee busy in a game. The game he planned for her is quite easy to play but not easy to win at least not for Dee Dee. But Dexter does not have time to spend on this silly task, so he wants your help.
There will be a button, when it will be pushed a random number N will be chosen by computer. Then on screen there will be numbers from 1 to N. Dee Dee can choose any number of numbers from the numbers on the screen, and then she will command computer to subtract a positive number chosen by her (not necessarily on screen) from the selected numbers. Her objective will be to make all the numbers 0.
Now she subtracts 2 from 2 and all the numbers become 0. Dexter is not so dumb to understand that this can be done very easily, so to make a twist he will give a limit L for each N and surely L will be as minimum as possible so that it is still possible to win within L moves.
But Dexter does not have time to think how to determine L for each N, so he asks you to write a code which will take N as input and give L as output.

Input

##
Input consists of several lines each with N such that 1 ≤ N ≤ 1,000,000,000. Input will be terminated by end of file.

Output

For each N output L in separate lines.

Sample Input

1 2 3

Sample Output

1 2 2


题意

给定一个正整数序列,每次可以从序列中选一个或多个数减去一个正整数。要使序列最终的值都为0,问最少的操作数为多少?


题解

对于每个不同的值x,显然可以通过减去x使得它的值最终为0.初始序列有n个不同的值,所以这种方法需要操作数为n。
要想办法减少操作数,就要通过操作将序列中的值尽可能的变成相同。
对于有n个数的序列,将[n/2+1,n]中的数都减去n/2+1,这样就使得不同的值只在[1,n/2]内。通过一次操作减少了n/2次操作。
所以,F(N)=F(N/2)+1.

代码

#include <cstdio>using namespace std;int f(int n)
{if(n==1) return 1;return f(n/2)+1;
}int main()
{int n;while(~scanf("%d",&n)){printf("%d\n",f(n));}return 0;
}

UVA 11384 Help is needed for Dexter (递归函数)相关推荐

  1. UVA11384 Help is needed for Dexter【数学】

    Dexter is tired of Dee Dee. So he decided to keep Dee Dee busy in a game. The game he planned for he ...

  2. UVA11384 Help is needed for Dexter (规律、思维)

    首先数据范围达到了1e9,这样的话哪怕O(n)O(n)O(n)的做法都不能过,所以我们手玩样例找规律 如果每次都减1的话,看上去减的数多,但是实际上需要n次,每次选择最大的减去全部,也需要n次,那么我 ...

  3. UVa11384 - Help is needed for Dexter(手玩大法)

    题目链接 简介: 给定正整数n,用最少的操作次数使得整个序列1,2,3,-,n都变成0 每次操作可以选择一个或多个整数,同时减去一个相同的正整数 分析: 手玩之后可以发现:每次都选择n/2的后半段删除 ...

  4. 贪心思维 专题记录 2017-7-21

    A.UVa 10382 - Watering Grass 题目大意: 有一块草坪,长为l,宽为w,在它的水平中心线上有n个位置可以安装喷水装置,各个位置上的喷水装置的覆盖范围为以它们自己的半径ri为圆 ...

  5. OI 刷题记录——每周更新

    每周日更新 2016.05.29 UVa中国麻将(Chinese Mahjong,Uva 11210) UVa新汉诺塔问题(A Different Task,Uva 10795) NOIP2012同余 ...

  6. 《算法竞赛入门经典——训练指南》第一章相关内容

    #<算法竞赛入门经典--训练指南>第一章相关内容 希望各位大牛能指导! 红色为已经做了的...黄色背景是还有不懂地方,希望在年前能刷完第一章啊.... 更新版.google上貌似又加了ex ...

  7. Vjudge 2016-5-10 math test

    刚刚讲完数论,善良的学长就为我们举办了一次紧张刺激的考(zuo)试(ti). A题 - A Simple Problem with Integers Description 给出了一个序列,你需要处理 ...

  8. Competitive Programming 3题解

    题目一览: Competitive Programming 3: The New Lower Bound of Programming Contests(1) Competitive Programm ...

  9. 【例题 6-21 UVA - 506】System Dependencies

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 记录每个物品它的依赖有哪些,以及它被哪些东西依赖就可以了. 显式安装的东西不能被隐式删除删掉(就是remove item,然后删除i ...

最新文章

  1. m.pythontab.com_Python expandtabs()函数的使用
  2. Fabric--启动网络手动
  3. 文件编码和RandomAccessFile文件流的使用--IO学习笔记(一)
  4. SpringBoot的配置优先级,一个具体的练习例子
  5. 哈佛终身教授刘军:生活在一个统计学的时代
  6. Delphi用ini文档实现界面无闪烁多语言转换
  7. redis——redis简介及基本交互方法
  8. poj 1703 并查集
  9. nsis打包php项目加环境,NSIS制作安装文件全攻略(一) zz
  10. 410.分割数组的最大值
  11. Minimax算法及实例分析
  12. Android添加图片水印
  13. 明御:APT攻击预警平台
  14. android 系统重新安装程序,安卓手机系统怎么重装
  15. linux 字幕制作工具,Arctime可视化字幕编辑器–做字幕从未如此简单
  16. jupyter notebook 打开ipynb时提示到后台服务的连接没能建立, 我们会继续尝试重连, 请检出网络连接...还有服务配置 命令行显示Replacing stale connection
  17. 去水印小程序好做吗?赚钱吗?
  18. 茅台nfc显示服务器临时维护,茅台酒使用手机NFC扫描瓶盖辨别真伪方法
  19. 嵌入式驱动程序(5-5)点灯大师⑤之TM1668
  20. python 累加累乘的函数reduce()

热门文章

  1. App磁盘沙盒工具实践
  2. SI 539 网站开发(二):week6
  3. 计算机为什么有网络凭证,Win10访问局域网中计算机共享文件显示需要网络凭证怎么办?...
  4. param name=allowScriptAccess value=never/是什么意思
  5. 北漂码农的真实心声:赚一线城市的钱,还二线城市的房贷
  6. WOT讲师杨钊:人工智能将在不同应用场景逐步落地
  7. excel数据透视表_Excel数据透视表排序问题
  8. Word 如何从任意页开始显示页码
  9. golang中的图像image处理详解
  10. createjs php通信,快速入门createjs实例教程