| # | Problem | Pass Rate (passed user / total user) |
|---|---|---|
| 11194 | Stairs Climbing |
|
| 11662 | Fill containers with water |
|
| 11834 | Tower of Hanoi |
|
Description
Bob is a man who wants to climb 3 step stairs.
Suppose he can only climb 1 or 2 step at a time.
Then , there are 3 possible ways to climb 3 step stairs
(1) 1 step + 1 step + 1 step
(2) 1 step + 2step
(3) 2 step + 1step
The question is : if Bob want to climb X step stairs.
How many possible ways are there to climp X step stairs.
Input
An integer N represents the number of testcases.
Then , there are following N lines.
Each line contain an integer X that represents the number of stairs in that testcase.
P.S. 1<= X <=40
Output
An integer represents the number of possible way to climb N stairs.
Note that you have to add '\n' at the end of output
Sample Input Download
Sample Output Download
Tags
Discuss
Description
Suppose that you have an infinite number of containers with different sizes, already filled with water. Given another empty container with size N liters, you need to find the best way to fill this N-liter empty container using the provided smaller containers. By ‘best’, we mean that the total number of used containers should be as small as possible. For example, assume that we have containers in 1, 5, and 10 liters. To get the 17 liters of water, we need 2 containers of 1 liter, 1 container of 5 liters, and 1 container of 10 liters. Another example: assume that we have containers in 1, 5, 10 and 50 liters. To get the 57 liters of water, we need 1 container of 50 liters, 1 container of 5 liters, and 2 containers of 1 liter. Note that, to avoid water wastage, if you choose to use a container, all the water in this container should be poured.
The following is an excerpt of incomplete code:
#include <stdio.h>
#define MAXNV 5
int DONE = 0;
int liters[MAXNV];
int numbers[MAXNV];
void show(int nv);
void filling(int amount, int cur, int nv);
int j=0;
int water;
int min=100;
int min_numbers[MAXNV]={0};
int main(void)
{
int nv, i;
scanf("%d", &nv);
for (i=0; i<nv; i++) {
scanf("%d", &liters[i]);
}
scanf("%d", &water);
filling(water, 0, nv);
for(i=0;i<nv;i++)
numbers[i]=min_numbers[i];
show(nv);
return 0;
}
void show(int nv)
{
int i;
printf("(%d", numbers[0]);
for (i=1; i<nv; i++) {
printf(",%d", numbers[i]);
}
printf(")\n");
}
void filling(int amount, int cur, int nv)
{
/* your code */
}
Input
The input contains three lines.
The first line contains an integer N, indicating that how many containers you have.
The second line gives you each container's size.
The last line is the total amount of water you have to pour.
Output
The result can be displayed by calling the function show().
Only the best way to fill the empty container should be displayed.
Sample Input Download
Sample Output Download
Tags
Discuss
Description
The Tower of Hanoi is a mathematical game puzzle. It consists of three rods, which are A, B and C. The puzzle starts with n disks in ascending order of size on rod A, the smallest at the top.
The objective of the puzzle is to move the entire stack to another rod, obeying the following simple rules:
1. Only one disk can be moved at a time.
2. Each move consists of taking the upper disk from one of the stacks and placing it on top of another stack i.e. a disk can only be moved if it is the uppermost disk on a stack.
3. No disk may be placed on top of a smaller disk.
Write a program to simulate the moves of the disks. Print the number of disk which is moved in each step.
For example, if n = 3, the moves of each steps are:
move disk 1 from rod A to rod C
move disk 2 from rod A to rod B
move disk 1 from rod C to rod B
move disk 3 from rod A to rod C
move disk 1 from rod B to rod A
move disk 2 from rod B to rod C
move disk 1 from rod A to rod C
You should print out:
1
2
1
3
1
2
1
HINT : You can modify this sample code and implement the function 'hanoi'
#include <iostream>
using namespace std;
void hanoi(int n, char A, char B, char C);
int main(){
int n;
cin >> n;
hanoi(n, 'A', 'B', 'C');
return 0;
}
Input
An integer n (0<n<20), which means the number of disk.
Output
Print out the number of disk which is moved in each step, and there is a '\n' at the end of each line.