zoukankan      html  css  js  c++  java
  • uva 11384 Help is needed for Dexter

    解题思路:对于 1~n, 保留 1~n/2, 把剩下的数同时减去 n/2+1, 得到 1, 2, ···, n/2, 0, 1, ···, (n-1)/2. 它等价于 1, 2, ···, n/2. 因此有如下递推关系:cal(1)=1, cal(n)=cal(n/2)+1 (n>=2). 

     1 ///////////////////////////////////////////////////////////////////////////
     2 //problem_id: uva 11384
     3 //user_id: SCNU20102200088
     4 ///////////////////////////////////////////////////////////////////////////
     5 
     6 #include <algorithm>
     7 #include <iostream>
     8 #include <iterator>
     9 #include <iomanip>
    10 #include <cstring>
    11 #include <cstdlib>
    12 #include <string>
    13 #include <vector>
    14 #include <cstdio>
    15 #include <cctype>
    16 #include <cmath>
    17 #include <queue>
    18 #include <stack>
    19 #include <list>
    20 #include <set>
    21 #include <map>
    22 using namespace std;
    23 
    24 ///////////////////////////////////////////////////////////////////////////
    25 #pragma comment(linker,"/STACK:1024000000,1024000000")
    26 
    27 #define lson l,m,rt<<1
    28 #define rson m+1,r,rt<<1|1
    29 ///////////////////////////////////////////////////////////////////////////
    30 
    31 ///////////////////////////////////////////////////////////////////////////
    32 const double EPS=1e-8;
    33 const double PI=acos(-1.0);
    34 
    35 const int x4[]={-1,0,1,0};
    36 const int y4[]={0,1,0,-1};
    37 const int x8[]={-1,-1,0,1,1,1,0,-1};
    38 const int y8[]={0,1,1,1,0,-1,-1,-1};
    39 ///////////////////////////////////////////////////////////////////////////
    40 
    41 ///////////////////////////////////////////////////////////////////////////
    42 typedef long long LL;
    43 
    44 typedef int T;
    45 T max(T a,T b){ return a>b? a:b; }
    46 T min(T a,T b){ return a<b? a:b; }
    47 T gcd(T a,T b){ return b==0? a:gcd(b,a%b); }
    48 T lcm(T a,T b){ return a/gcd(a,b)*b; }
    49 ///////////////////////////////////////////////////////////////////////////
    50 
    51 ///////////////////////////////////////////////////////////////////////////
    52 //Add Code:
    53 int cal(int n){
    54     if(n==1) return 1;
    55     return cal(n/2)+1;
    56 }
    57 ///////////////////////////////////////////////////////////////////////////
    58 
    59 int main(){
    60     ///////////////////////////////////////////////////////////////////////
    61     //Add Code:
    62     int n;
    63     while(scanf("%d",&n)!=EOF) printf("%d
    ",cal(n));
    64     ///////////////////////////////////////////////////////////////////////
    65     return 0;
    66 }
    67 
    68 ///////////////////////////////////////////////////////////////////////////
    69 /*
    70 Testcase:
    71 Input:
    72 1
    73 2
    74 3
    75 Output:
    76 1
    77 2
    78 2
    79 */
    80 ///////////////////////////////////////////////////////////////////////////
  • 相关阅读:
    linux运维 技能树
    ORACLE:毫秒与日期的相互转换,获取某天的信息
    Mybatis通用Mapper(转)
    Redis数据类型之散列类型hash
    Redis数据类型(字符串)
    Redis整理第三波(生存时间、事务管理)
    Redis整理第二波(启动、命令)
    非关系型数据库(NOSQL)-Redis
    冒泡排序,冒泡性能优化--java实现
    学习过的设计模式总结(分别从概念、分类、优缺点、应用、区别来说)
  • 原文地址:https://www.cnblogs.com/linqiuwei/p/3317350.html
Copyright © 2011-2022 走看看