HDU-5703-Desert2016CCPC女生专场

Posted 宣之于口

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了HDU-5703-Desert2016CCPC女生专场相关的知识,希望对你有一定的参考价值。


HDU-5703-Desert


Problem Description
A tourist gets lost in the desert with n liters of water. He drinks positive integer units of water each day.

Write a program to calculate how many different ways the tourist can drink up the water.

Input
The first line contains the number of test cases T(T≤10).
Next T lines contain the number n(1≤n≤1000000) for each test case.

Output
Output consists of T lines.
Each line contains the binary number which represents number of different ways to finish up the water specified in the test case.

Sample Input
1
3

Sample Output
100

题目链接:HDU-5703

题目大意:3可以表示为1 1 1,1 2,2 1,3,4种方法。那么任意输入一个n可以表示为几种方法,结果用二进制表示

题目思路:可以发现,方法数为2^(n-1),但是要用二进制表示,那么输出第一位为1,接下来n-1个0就可以

以下是代码:

//
//  5703.cpp
//  2016-CCPC-GIRL
//
//  Created by pro on 16/7/3.
//  Copyright (c) 2016年 loy. All rights reserved.
//

#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <algorithm>
#include <string>
#include <set>
#include <functional>
#include <numeric>
#include <sstream>
#include <stack>
#include <map>
#include <queue>
#include<iomanip>
using namespace std;

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

以上是关于HDU-5703-Desert2016CCPC女生专场的主要内容,如果未能解决你的问题,请参考以下文章

hdu-5703 Desert(水题)

HDU5703 Desert水题

HDU-5706-GirlCatBFS2016CCPC女生专场

HDU-5707-Combine String2016CCPC女生专场DP

2018CCPC-女生专场

2021ccpc女生专场