题目链接: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
- 2 1
- 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;
}