1621: 减小数

作者: Celia_QAQ | 来源:发表于2019-07-04 22:00 被阅读0次

    Description
    给定一个数n,你的任务是用最少的操作把1,2.......n中的所有数都变成0。每次操作可以从序列中选择一个或多个同时减去一个数。
    Input
    输入n(n<=100000)
    Output
    输出最小次数
    Sample Input
    1
    2
    Sample Output
    1
    2

    参考:https://blog.csdn.net/qq_38735931/article/details/82661802
    思路:找规律,然后神奇的事情就发生了,代码要多简洁有多简洁
    AC代码:

    #include<vector>
    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<cmath>
    #include<map>
    #include<algorithm>
    using namespace std;
    typedef long long ll;
    const int maxn=300050;
    
    int main(){
       int t,temp,m,n,count;
        int a[maxn];a[0]=0;
        while(~scanf("%d",&t)){
            count=0;
        while(t){
            count++;
            t/=2;
            
            }
             printf("%d\n",count); 
       }
    
         return 0;
    }
    

    相关文章

      网友评论

        本文标题:1621: 减小数

        本文链接:https://www.haomeiwen.com/subject/ygmdhctx.html