| # | Problem | Pass Rate (passed user / total user) |
|---|---|---|
| 10664 | easy 8 Puzzles |
|
| 11498 | Count the Leaves |
|
| 12264 | NPK-easy |
|
| 12266 | Looking for Chinese Tutor |
|
| 12306 | beat the monster |
|
| 12330 | Treasure Hunting |
|
| 13223 | Maximum of Interval |
|
| 13236 | easy 8 Puzzles (English version) |
|
Description
一個八數字推盤遊戲由3*3的棋盤組成,每一個格子上都有一個數字(0~8且不重複),一開始盤面是亂的,
| 1 | 2 | 3 |
| 4 | 0 | 5 |
| 7 | 8 | 6 |
每次操作可以將0與其上.下.左.右的數字互換,經過若干次操作:
step 1 : 0往右與5互換
| 1 | 2 | 3 |
| 4 | 5 | 0 |
| 7 | 8 | 6 |
step 2 : 0往下與6互換
| 1 | 2 | 3 |
| 4 | 5 | 6 |
| 7 | 8 | 0 |
最後將盤面排回
| 1 | 2 | 3 |
| 4 | 5 | 6 |
| 7 | 8 | 0 |
即為正解。
Rody最近沉迷於八數字推盤遊戲當中,但最近要開始期末大爆炸了,Rody不再那麼空閒,因此他決定要先跳過太過困難的題目,等到暑假再來解。
困擾的Rody想要請你幫他鑑定題目的困難度。
Input
input第一行有一整數T(1<=T<=30),代表底下有T筆測資。
第2~T+1行分別有9個不同的整數(0<=t1,t2,...,t9<=8),代表一個八數字推盤遊戲。
(註:9個整數以row major方式填入3*3的盤面,如第二組測資 1 2 3 4 0 5 7 8 6 等同於下方示意圖)
| 1 | 2 | 3 |
| 4 | 0 | 5 |
| 7 | 8 | 6 |
Output
對於每組八數字推盤遊戲,若能在14步內完成遊戲,請輸出"You can solve it within x steps.",x為解決該遊戲所需的最少移動次數。
否則,請輸出"You'd better skip this game."
Sample Input Download
Sample Output Download
Tags
Discuss
Description
Given a tree, count the number of leaves in this tree. Each node has unique integer identification (ID), but all IDs may not be consecutive.
Input
There are multiple test cases. Each test case begins with an integer N (1 <= N <=1000). In the following N lines, each line has two integer a and b (1 <= a,b <= 1000), indicating node a is node b’s parent. The next line contains an integer R, which represents the root of the Tree. You can assume that all the nodes will be on the same tree. The input is terminated by N = 0.
Output
Print the number of the leaves for each test case.
Hint: All leaves have no children!
Sample Input Download
Sample Output Download
Tags
Discuss
Description
Price of fertilizers in the world are raising! Adding Jinkela in fertilizer, one bag can cover two bags!!
People from America, Africa, Japan are lining up in a queue to buy Jinkela. Each person is given a unique id x. The country of each person can be identified by the remainder of his id divided by 3. If x mod 3 = 0, he is from America; if x mod 3 = 1, he is from Africa; if x mod 3=2, he is from Japan. Lining up is tedious, everyone wants to cut in line! These American, African, and Japanese follow some rule when they cut in line:
When a person enters the queue,
- If the queue is empty, he becomes the first person in the queue.
- If there isn't anyone who comes from the same country in the queue, he becomes the last person in the queue.
- Otherwise, of all people coming from the same country in the queue, he finds the last of them and lines up after him ( and possibly cuts in line ).
After a person buys Jinkela, he leaves the queue immediately and will not enter the queue again.
You are curious about the order people get their Jinkela. Given the status of the queue. Whenever someone leaves the queue, output his id.
Refer to the sample IO for example if you don't understand the rule.
For example, assume the queue is empty initially.
- ENQUEUE 0: An American with id 0 enters the queue. Since the queue is empty, he becomes the first person in the queue
queue: 0
- ENQUEUE 1: An African with id 1 enters the queue. Since there isn't any other African in the queue, he becomes the last person in the queue.
queue: 0 1
- ENQUEUE 3: An American with id 3 enters the queue. Since he finds an American (id=0) in the line, he lines up right after him.
queue: 0 3 1
- ENQUEUE 6: An American with id 6 enters the line. He finds two American (id=0, id=3) in the line, where American with id 3 is the last one, he lines up after American with id 3.
queue: 0 3 6 1
- DEQUEUE: The first person leaves the line. Output his id(0).
queue: 3 6 1 output: 0
Input
The status of queue is represented as several commands.
The first line of Input consists of a single integer n (n ≦ 10^6), indicating there are n commands in total.
The following n lines are the commands. There are two kinds of commands:
- ENQUEUE x: person with id x enters the queue. x is an integer, 0 ≦ x ≦ 10^6
- DEQUEUE: the first person in the queue buys his Jinkela and leaves the queue
Output
For each DEQUEUE command, please output the id of person who leaves the queue.
Each output occupies a single line.
Sample Input Download
Sample Output Download
Tags
Discuss
Description
Hurry! Hurry! Hurry! Wanted!!!
Rumor has it that students in NTHU and NCTU are very friendly. Whenever someone is looking for a Chinese tutor ( especially when that person is in a hurry ), students will recommend their classmates if they know their classmates are capable of being a nice Chinese tutor. Students will tag their classmates in a special format : "classmate_name the school_name pokemon_name"
For example, "王小明清大小鋸鱷" would be "Wangxiaoming the NTHU Waninoko" in English.

Since students in NTHU and NCTU are well educated, they will choose a suitable water type pokemon based on beginning rhymes. They organized a beginning rhymes list. Students can find what pokemon their classmates should be by checking the list. For classmates who can't find a suitable pokemon in the list, we say that they are not good at Chinese.
| Names starting with ... | Name of suitable pokemon |
|---|---|
| Wa | Waninoko |
| Mi | Milotic |
| Ma | Magikarp |
| Va | Vaporeon |
| Sh | Sharpedo |
| Tapu | Tapu Fini |
| Em | Empoleon |
| La | Lapras |
| Pi, Pe | Pikachu |
| Me | Mega Gyarados |
For example, since WangXiaoMing starts with "Wa", studnets will find a pokemon whose name starts with "Wa".
You want to recommend some of your classmates. Given the names of your classmates and the schools they study in. Please tag your classmates using the special format mentioned above.
Input
The first line contains a single integer n, meaning that you have n classmates to recommend.
The n following lines. Each consists of two strings : name of your classmate and the school he studies in.
It is guarenteed that ...
- lengths of your classmates' names and schools' names will be more than 1, less than 100.
- Every name of your classmates contains english alphabets only, starting with an upper-case character, followed by lower-case characters.
Output
For each of your classmates,
- If you can find a suitable pokemon based on the list, please output using the special format : "classmate_name the school_name pokemon_name" (without quotation mark)
- If you cannot find a suitable pokemon based on the list, please output "classmate_name is looking for a Chinese tutor, too!" (without quotation mark)
Each output occupies one line.
Notes for Sample IO
- Since "Tanner" doesn't start with "Tapu", so he isn't "Tanner the NCTU Tapu Fini"
- According to the list, names starting with "Pi" or "Pe" can be Pikachu, therefore "Peter" is "Peter the NCTU Pikachu"
Useless Hints
Why is Pikachu in the list? Go google search for "surfing pikachu" XDD.
Sample Input Download
Sample Output Download
Tags
Discuss
Description
You are playing a game. The goal of this game is to kill the monster when you are still alive (HP > 0, HP = health point). The monster is dead if and only if its HP <= 0.
This game consists of rounds, and you go first in each round.
You have 3 options in each round:
- ATTACK. This will deduct the monster's HP. If your damage point is p, then you can deduct p monster's HP.
- HEAL. You can recover some of your HP, but it can't exceed your max HP.
- Level-up. Level-up might enhance the effect of attacking or healing, but if you are not lucky enough, sometimes it will deduct the effect of attacking and healing. Thus, choosing to level-up is not always a good choice. If you have reached max level, taking this action makes no effect.
In each round, the monster will attack you once with a fixed damage point.
You start the game with full HP and level 1. What is the minimun number of rounds you need to kill the monster?
Input
First line contains 4 numbers L, HP, MHP, MDMG.
- L = max level
- HP = your max HP
- MHP = monster's HP in the beginning of game
- MDMG = monster's damage point
The next L lines describes each level, i-th line of them describes level i. Each of them consists of two numbers, DMG and HL.
- DMG = your damage point when you use ATTACK at level i
- HL = amount of HP you can recover when you use HEAL at level i
Limits:
- L <= 15
- HP <= 300
- MHP <= 400
- MDMG <= 10000
- DMG <= 10000
- HL <= 50
Output
Print a single integer, denoting the mininum number of steps you need to kill the monster.
If you are unable to beat the monster, print -1.
Sample Input Download
Sample Output Download
Tags
Discuss
Description
Niflheimr is playing Minecraft recently. He occupies a lot of towns, and there are many diamonds inside some of those towns.
Whenever he runs out of diamond, he has to figure out the nearest town with diamonds from his current location.
Doing this task every time waste a lot of time. He asks you to help him for the calculation. For every town, find the shortest distance to get diamonds from a nearby town which has diamonds. If the town itself has diamonds, the distance would be 0.
Hint: Use BFS (Breadth First Search) and std::queue.
You are provided with the following code:
#include <queue>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
// G[i] is the neighbor towns of town i
vector<int> diamondTowns;
vector<int> G[100005];
int Dist[100005];
struct node {
int id;
int dist;
node(int id, int l) {
this->id = id;
this->dist = l;
}
};
int main() {
int N, M, K;
cin >> N >> M >> K;
for (int i = 0; i < M; i++) {
int a, b;
cin >> a >> b;
G[a].push_back(b);
G[b].push_back(a);
}
for (int i = 0; i < K; i++) {
int x;
cin >> x;
diamondTowns.push_back(x);
}
fill(Dist, Dist+100005, -1);
queue<node> Q;
// [TODO] complete the task!
// Output
for (int i = 1; i <= N; i++) {
cout << Dist[i] << '\n';
}
return 0;
}
You may take it as reference. You are not required to use this code, though.
Input
First line of input contains three integer N, M, K, denoting the number of towns, the amount of roads between towns and the number of towns which has diamond.
All the towns are numbered from 1 to N.
For the next M lines, each of them contains two integer a, b, meaning there is a road between a and b. All the roads are bidirectional, and the length of these roads are all 1.
The last line of input contains K distinct integers, denoting the towns which has diamonds.
It is guaranteed that:
- 1 <= K <= N <= 105
- 1 <= M <= min(106, N*(N+1)/2)
- All the towns can reach each other, i.e. the graph is connected.
Output
Output consists of N lines.
For i-th line, output the shortest distance Niflheimr has to travel from town i to get a diamond.
Sample Input Download
Sample Output Download
Tags
Discuss
Description
Given a sequence a1, a2, ..., aN, and an positive integer L.
Let M(i) be the maximum among ai, ai+1, ..., ai+L-1.
For each i = 1, ..., N-L+1, please find the answer to M(i).
To prevent TLE, add the following code at the first line of your main function and don't use endl in your code.
ios::sync_with_stdio(0); cin.tie(0);
Input
The first line of the input contains two integers N L.
The second line contains N numbers a1, a2, ..., aN.
For i = 1, ..., N, |ai| <= 106.
L <= N.
- For testcase 1 and 2, N <= 100.
- For testcase 3 and 4, N <= 5000.
- For testcase 5 and 6, N <= 1000000.
Output
Please output N-L+1 numbers as the answers.
Remember to add new line in the end.
Sample Input Download
Sample Output Download
Tags
Discuss
Description
Note: This is just the translation of "10664 - easy 8 Puzzles" in English. Please submit your code to "10664 - easy 8 Puzzles".
Given a 3×3 board with 9 tiles and every tile has one number from 0 to 8.
| 1 | 2 | 3 |
| 4 | 0 | 5 |
| 7 | 8 | 6 |
We can swap ‘0’ with its four adjacent (left, right, above, and below) tiles. For example:
step 1 : swap 0 with ‘5’
| 1 | 2 | 3 |
| 4 | 5 | 0 |
| 7 | 8 | 6 |
step 2 : swap 0 with ‘6’
| 1 | 2 | 3 |
| 4 | 5 | 6 |
| 7 | 8 | 0 |
The objective is to place the numbers on tiles to match the following configuration.
| 1 | 2 | 3 |
| 4 | 5 | 6 |
| 7 | 8 | 0 |
(Noting important in this paragraph, something like Rody is too busy and needs your help to solve this problem.)
Input
Given T (1<=T<=30) in the first line, saying that there will be T test cases.
From 2nd line to (T+1)-th line, each line contains 9 distinct integers from 0 to 8, representing an 8-puzzle game. Nice integers will be filled to the 3×3 board in a row-major manner. For example, 1 2 3 4 0 5 7 8 6 will become the configuration as shown in the following figure.
| 1 | 2 | 3 |
| 4 | 0 | 5 |
| 7 | 8 | 6 |
Output
For each 8-puzzle game, if it can be solved in 14 steps, print out "You can solve it within x steps.", x is the minimum number of steps to solve this puzzle. Otherwise, print out "You'd better skip this game.