HDU-5703-Desert【2016CCPC女生专场】


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;
}
已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 技术黑板 设计师:CSDN官方博客 返回首页