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.
    For example if N = 3, then on screen there will be 3 numbers on screen: 1, 2, 3. Say she now selects 1 and 2. Commands to subtract 1, then the numbers on the screen will be: 0, 1, 3. Then she selects 1 and 3 and commands to subtract 1. Now the numbers are 0, 0, 2. 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

问题链接:UVA11384 Help is needed for Dexter
问题简述:(略)
问题分析
    给定一个N,对1-N这N数,选出若干个数,对这些数都减去某个数,重复这样的操作,问最少几次后所有的数都变为0。
例如:
1 2 3 4 5
先对后3个,都减去3,则变为:
1 2 0 1 2
对于所有的2,都减去2,则变为:
1 0 0 0 1
再对于所有的1,都减去1,则变为:
0 0 0 0 0
    对于给定的N,先考虑起中值,中值右边所有数都减去中值,至少1个数已经变为0。然后从新排序,重复这个过程。这样可以得出所有数变为0需要做减法的次数是f(n)=1+f(n/2)。
    对以上的递推式,需要找出其规律,然后再打表搜索即可。对公式f(n)=1+f(n/2),可以找出其中的规律,那就是换1次的有2^0(N=1)个,2次的有2^1(N=2-3)个,需要换3次有2^2(N=4-7)个,需要换4次有2^3(N=8-15)个,…
程序说明:(略)
参考链接:(略)
题记:(略)

AC的C++语言程序如下:

/* UVA11384 Help is needed for Dexter */#include <bits/stdc++.h>using namespace std;//int f(int n)
//{//    if(n == 1) return 1;
//    else return 1 + f(n / 2);
//}const int N = 32;
int dp[N];void init()
{//    for(int i = 1; i <= 17; i++)
//        printf("%d %d\n", i, f(i));int t = 1;for(int i = 0; i < N; i++)dp[i] = t << i;
}int main()
{init();int n;while(~scanf("%d", &n))for(int i = 0; i < N; i++)if(n >= dp[i] && n <= dp[i + 1] - 1) {printf("%d\n", i + 1);}return 0;
}

UVA11384 Help is needed for Dexter【数学】相关推荐

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

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

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

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

  3. UVA 11384 Help is needed for Dexter (递归函数)

    题目链接 https://vjudge.net/problem/26096/origin 题目 Dexter is tired of Dee Dee. So he decided to keep De ...

  4. Competitive Programming 3题解

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

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

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

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

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

  7. Vjudge 2016-5-10 math test

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

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

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

  9. 2017美国数学建模ICM E题(环境) 翻译 需要可持续城市!(Sustainable Cities Needed!)

    问题E:需要可持续城市!((Sustainable Cities Needed!)) 背景: 许多社区正在实施智能增长计划,以考虑长期,可持续的规划目标. "聪明的成长是关于帮助每个城镇和城 ...

最新文章

  1. php set medias,laravel5.1 -- Integrate FileManager and CKeditor into laravel
  2. RDKit | 基于最大公共子结构(MCS)的分子比对
  3. SPFA算法O(kE)
  4. c#listView
  5. 前端怎么导出表格_前端如何导出表格数据
  6. php类如何变为静态调用,PHP类中静态方法如何调用非静态方法?_后端开发
  7. 微软Scott CIO也要代表公司拜访客户
  8. 未来教育计算机二级第一套ppt解析,计算机二级未来教育PPT部分答案
  9. Linux经常使用到的操作
  10. 处理文章附件路径问题
  11. MySQL-第四篇索引
  12. 网吧用服务器做虚拟化,刀片、无盘、集群、虚拟化,给你一个选择的理由(上)...
  13. 用计算机看手机照片大小,手机怎么知道照片多少k
  14. 计算机Excel电子表格处理文件,2018计算机应用基础-Excel电子表格题目
  15. 看单片机原理图-电源电路
  16. 手机浏览器怎么下载视频,第三方手机浏览器下载视频的方法
  17. 多个订单待付款半小时倒计时功能
  18. 【spring】spring 的事务(transaction) 四 嵌套事务PROPAGATION_NESTED
  19. 黑白方格画C++解答
  20. liunx oracle 12505,ORA-12505 错误解决

热门文章

  1. 团队协助 开源项目_适合小团队的协作工具,良心开源项目管理工具
  2. 用python画大白圣诞快乐呦
  3. Spark性能优化:Shuffle调优篇
  4. Sqoop 数据增量导出,--update-key添加多个字段
  5. c++多数据平均数_定量分析中的几个概念-平均数、算数平均数、调和平均数以及权重及应用...
  6. 迷宫问题python实现
  7. java 传xml js_JavaScript实现的XML与JSON互转功能详解
  8. android中注册代码怎么写,Android P HIDL demo代码编写 (原创)
  9. matlab pwlech,MATLAB功率谱函数pwelch 和specture.welch
  10. 剑指offer面试题31. 栈的压入、弹出序列(链表)