UVa11384 Help is needed for Dexter (思维)

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了UVa11384 Help is needed for Dexter (思维)相关的知识,希望对你有一定的参考价值。

链接:http://acm.hust.edu.cn/vjudge/problem/26096
分析:带几个栗子进去发现,序列1,2,...,n,为了平衡将(n/2+1)~n的数同时减去(n/2+1),得到1,2,...n/2,0,1,...(n-1)/2,它等价于1,2,...,n/2,因此f(n)=f(n/2)+1,边界是f(1)=1。

 1 #include <cstdio>
 2 
 3 int f(int n) {
 4     return n == 1 ? 1 : f(n / 2) + 1;
 5 }
 6 
 7 int main() {
 8     int n;
 9     while (scanf("%d", &n) == 1) {
10         printf("%d\n", f(n));
11     }
12     return 0;
13 }

 

以上是关于UVa11384 Help is needed for Dexter (思维)的主要内容,如果未能解决你的问题,请参考以下文章

uva 11384 Help is needed for Dexter

[UVa 11384]Help is needed for Dexter

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

UVA 11384 正序数排列

[HDU1712]ACboy needs your help

UVA11161 Help My Brother (II)大数+递推