Desert——整数划分

该博客介绍了当一名游客在沙漠中迷路并拥有n升水时,如何计算以正整数单位喝水的不同方式。这是一个整数划分问题,例如给定3升水,有4种不同的喝法。程序输出用二进制表示的喝光所有水的方式数,如3升水对应100(二进制)表示4种方式。
摘要由CSDN通过智能技术生成

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)T(T≤10).
Next TT lines contain the number n(1≤n≤1000000)n(1≤n≤1000000) for each test case.
Output
Output consists of TT 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

题意:n升水,每次喝正整数升水,有多少种喝法;
分析:整数划分问题,3分为1+1+1,1+2,2+1,3一共四种
n能分解为2的n-1次方种,转化为二进制,就是一个1,n-1个0.

#include<stdio.h>
#include<string.h>
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int i,n;
        scanf("%d",&n);
        printf("1");
        for(i=1;i<n;i++)
            printf("0");
        printf("\n");
    }
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值