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

86 篇文章 9 订阅
9 篇文章 0 订阅

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;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值