HDU - 5703 Desert(巧用二进制)

题目链接https://vjudge.net/contest/357089#problem/C

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

Hint
3 liters of water can be comsumed in four different ways show in the following.

  1. 1 1 1
  2. 1 2
  3. 2 1
  4. 3

If we write 4 in binary, it’s 100.

翻译
刘天泽很喜欢喝酱油。他从超市里一次性买了n瓶酱油带回家。由于酱油是他每天吃饭必不可少的东西,所以只要他还有酱油,一天里至少要喝掉一瓶酱油,并且刘天泽一喝就会把整瓶喝掉,不会余下瓶中的部分酱油留到第二天。一直到所有的酱油喝完为止。他想要知道,自己一共有多少种喝酱油的方案。两种方案被认为是不同的,当且仅当刘天泽买的这些酱油能喝的天数不同,或者存在一天两种方案喝的酱油瓶数不同

分析
对于每一个n,可以分成的表达式是多少个。
通过分析,对于每一个n,输出的结果是2的n-1次方
又因为题目是要输出结果的二进制表达形式。可以知道直接输出一个1和n-1个0即可

代码

#include<cstdio>
#include<cstring>
#include<math.h>
#include<stdlib.h>
#include<algorithm>
using namespace std;
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int n;
        scanf("%d",&n);
        printf("1");
        for(int i=1; i<n; i++)
            printf("0");
        printf("\n");
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

zaiyang遇见

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值