741 - 103 資料結構導論Mid exam 1 Scoreboard

Time

2015/04/27 15:30:00 2015/04/27 17:30:00

Clarification

# Problem Asker Description Reply Replier Reply Time For all team

# Problem Pass Rate (passed user / total user)
10552 2D point sorting
10553 Joseph Episode II
10554 Expedition

10552 - 2D point sorting   

Description

Given N points on a 2D plane, please sort these points. Two points are compared by the following rules:
1. If the x coordinates are different, the point with the smaller x coordinate wins.
2. If the x coordinate are the same, then point with the smaller y coordinate wins.

The winner point should output before loser point!
Input will ensure that no two points are at the same position.

Input

Input begins with an integer T, the number of test cases. Each test case would be in the following format.
Line 1: An integers: N, means the number of 2D point.
The following are N lines.
Line i (2<=i<=N+1): Two integers: x y, separated by a blank, indicating the x and y coordinate of ith point.

limits :

subtask 1 : (when you pass this subtask, you can get 20 point)
1 <= N <= 1000
0 <= x,y <= 1000000
Using O(N^2) sorting algorithm is okay!

subtask 2 : (when you pass this subtask, you can get another 20 point)
1 <= N <= 100000
0 <= x,y <= 1000000
You have to use O(NlogN) sorting algorithm!

Output

For each test case outputs N lines, the sorting result.

Sample Input  Download

Sample Output  Download

Tags




Discuss




10553 - Joseph Episode II   

Description

The rule of the original Joseph game is quite simple.
At first, N people forms a circle and the person with number 1 holds the knife.
Each round, the person with knife kills the person after him and
passes the knife to the next person.

To make the game more intersting, the person with knife
kills the person who is K people after him (not always his neighbor),
and passes the knife to the person after the one being killed.

In your homework, we count and pass the knife clockwisely.
Now, we will do this in counter-clockwise way. For example,
If there are 10 people and K=3 at first.
In first round, the knife is initially hold by #1 and will be pass to #8.
Then, #7 will be killed and the knife is pass to #6.
Finally, #9 will survive.

 

Input

There several test cases. The input will terminate with EOF.
Each test case contains one line with two integer N and K seperated by a space.

limits :

subtask 2 : (when you pass this subtask, you can get 20 point)
1 <= N <= 100
0 <= K <=N
Using O(N^3) algorithm is okay!
You can kill each person in O(N^2)!

subtask 1 : (when you pass this subtask, you can get another 20 point)
1 <= N <= 100000
0 <= K <= N
You have to use O(NK) algorithm!
That is, you have to kill each person in O(K)!

Output

For each testcase, output a line with one integer.
Which is the final survivor of each test case.

Sample Input  Download

Sample Output  Download

Tags




Discuss




10554 - Expedition   

Description

A group of cows grabbed a truck and ventured on an expedition deep into the jungle. Being rather poor drivers, the cows unfortunately managed to run over a rock and puncture the truck's fuel tank. The truck now leaks one unit of fuel every unit of distance it travels.

To repair the truck, the cows need to drive to the nearest town (no more than 1,000,000 units distant) down a long, winding road. On this road, between the town and the current location of the truck, there are N (1 <= N <= 10,000) fuel stops where the cows can stop to acquire additional fuel (1..100 units at each stop).

The jungle is a dangerous place for humans and is especially dangerous for cows. Therefore, the cows want to make the minimum possible number of stops for fuel on the way to the town. Fortunately, the capacity of the fuel tank on their truck is so large that there is effectively no limit to the amount of fuel it can hold. The truck is currently L units away from the town and has P units of fuel (1 <= P <= 1,000,000).

Determine the minimum number of stops needed to reach the town, or if the cows cannot reach the town at all.

The idea of solving this problem is repeatedly do:
- if we can reach the town without any further more fuel, end
- if not, choose the best available stop(with max amount of fuel and not chosen yet)[Greedy strategy]

Input

* the first line: A single integer, T: the number of testcases

for each testcase: 

* Line 1: A single integer, N 

* Lines 2..N+1: Each line contains two space-separated integers describing a fuel stop: The first integer is the distance from the town to the stop; the second is the amount of fuel available at that stop. 

* Line N+2: Two space-separated integers, L and P

limits : 

subtask 1 : (when you pass this subtask, you can get 20 point)
1 <= N <= 10000
Using O(N^2) algorithm is okay!


subtask 2 : (when you pass this subtask, you can get another 20 point)
1 <= N <= 10000

only O(NlgN) algorithm is okay!

Output

* Line 1: A single integer giving the minimum number of fuel stops necessary to reach the town. If it is not possible to reach the town, output -1.

Sample Input  Download

Sample Output  Download

Tags

ddd



Discuss