UVa 11384 Help in needed for Dexter 正整数序列

序列太简单了,每次对于后面一半进行操作,使之变成前一半就行了。

i个数需要操作的次数

f(i)=f(i/2)+1

代码如下:

#include<cstdio>
using namespace std;

int f(int n){
    return n==1?1:f(n/2)+1;
}

int main(){
    int n;
    while(scanf("%d",&n)==1)
        printf("%d\n",f(n));
    return 0;
}

原文地址:https://www.cnblogs.com/lingyuanchuang/p/9595213.html

时间: 2024-10-08 21:27:21

UVa 11384 Help in needed for Dexter 正整数序列的相关文章

uva 11384 Help is needed for Dexter(模拟)

uva 11384 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 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 th

UVA - 11384 - Help is needed for Dexter (找规律!!)

UVA - 11384 Help is needed for Dexter Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & %llu Submit Status Description Problem H Help is needed for Dexter Time Limit: 3 Second Dexter is tired of Dee Dee. So he decided to keep Dee Dee b

UVA 11384 Help is needed for Dexter

#include<iostream> using namespace std; int n; int dfs(int n){return n == 1 ? 1 : dfs(n / 2) + 1;} int main() { while (cin >> n) cout << dfs(n) << endl; return 0; }

uva------Help is needed for Dexter(11384)

Problem H Help is needed for Dexter Time Limit: 3 Second 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 hav

【UVA11384】Help is needed for Dexter(数学题。。。)

Problem H Help is needed for Dexter Time Limit: 3 Second 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 hav

和为S的连续正整数序列

package wangChaoPA实习工作练习.com.剑指offer;import java.util.ArrayList;/* * 解题思路:因为是连续的,所以利用大小数进行解答 如果从little到big的和等于sum * 保存little到big值到list中然后,little++,big++ 如果从little到big的和小于sum big++ * 如果从little到big的大等sum little++ */public class 和为S的连续正整数序列{    public A

26.打印所有和为S的连续正整数序列

http://zhedahht.blog.163.com/blog/static/25411174200732711051101 题目: 输入一个正数n,输出所有和为n连续正数序列.例如输入15,由于1+2+3+4+5=4+5+6=7+8=15,所以输出3个连续序列1-5.4-6和7-8. 分析: 这是网易的一道面试题.这道题和本面试题系列的第10题有些类似.我们用两个数small和big分别表示序列的最小值和最大值.首先把small初始化为1,big初始化为2.如果从small到big的序列的

一道笔试题-给定一个正整数序列,请尝试将它们重新排列使得排列的结果最大。

问题描述:给定一个正整数序列,请尝试将它们重新排列使得排列的结果最大,例如正整数序列为9,31,35,3,7则最大值为9735331. 思路分析:先将正整数序列转换为字符串数组,然后字符串数组进行排序,最后依次输出字符串数组即可.根据题目的要求,两个数字m和n排成的数字mn和nm,如果mn<nm,那么我们应该输出nm,也就是m应该排在n的后面,也就是m<n.反之,如果nm<mn,m排在n的前面,n<m.如果mn==mn,m等于n. 比较函数的定义是本解决方案的关键.这道题其实就是希

编程算法 - 和为s的连续正整数序列 代码(C)

和为s的连续正整数序列 代码(C) 本文地址: http://blog.csdn.net/caroline_wendy 题目: 输入一个正数s, 打印出所有和为s的连续正数序列(至少含有两个数). 起始于1, 2, 相加, 如果相等则返回, 如果小于, 则前端递增右移, 如果大于, 则后端递增右移, 一直到后端移动到s的一半位置. 因为两个数, 小数为一半, 大数为一半加一, 则必然结束. 代码: /* * main.cpp * * Created on: 2014.6.12 * Author: