| # | Problem | Pass Rate (passed user / total user) |
|---|---|---|
| 11209 | N queens |
|
| 11662 | Fill containers with water |
|
| 11679 | Flattening the Tree |
|
Description
You have to place N queens on an N-by-N chessboard in a way that no two queens attack each other.
The rule is that each row, column, and diagonal of the board contains exactly one queen.
Your mission is to compute how many possible ways to place N queens on that chessboard.
Input
An integer N that represents the size of chessboard and the number of queens.
where 1<=N<=10
Output
An integer that represents the number of possible placements of N queens.
There is no need 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
Writer : jjjjj19980806
Description : pclightyear
In this problem, we want you to use an array A to implement a perfect binary tree (a kind of binary tree which all interior nodes have two children and all leaves have the same depth or same level.). Given the level order sequence of the tree, please output the sequence of number after the tree is flattened.
For example, a perfect binary tree with level order sequence 4 2 6 1 3 5 7 looks like :
After flattening, so you should output 1 2 3 4 5 6 7.
Here is some tips for you guys to implement a binary tree.
1. A[1] is the root of the tree.
2. For the node locates in A[k], its left child locates in A[2k] and its right child locates in A[2k+1].
3. You can write a recursive function "find_seq" which takes the root index as its argument.
Input
The first line contains one integer n, representing the number of nodes in the tree.
The second line contains n integer ai, representing the level order of the tree.
It is guaranteed that :
- n = 2k - 1
- 1 ≤ k ≤ 10
- a1 ~ an is a permutation of 1 ~ n
Output
Please output the sequence of the number after the tree is flattened. Each number is separated by a whitespace.
You need to print ‘\n’ at the end of the output.