HDU 5703(Desert)找规律

题目链接:https://vjudge.net/problem/HDU-5703

题意:输入一个数 判断这个数可有多少种累加方式,输出为二进制

比如对n=3

3=3;

3=2+1;

3=1+2;

3=1+1+1;

共四种,输出4的二进制100。

找规律可得最后的答案为2^(n-1),即1个1后面跟着(n-1)个0

#include<bits/stdc++.h>
#define maxn 1000010
#define LL long long
using namespace std;

int main()
{
   int T;
   while(cin>>T)
   {
       while(T--)
       {
           int n;
           cin>>n;
           cout<<1;
           for(int i=0;i<n-1;i++)
           {
               cout<<0;
           }
           cout<<endl;
       }
   }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/eknight123/article/details/80279015