# | Problem | Pass Rate (passed user / total user) |
---|---|---|
14152 | TsingHua Arena |
|
14156 | Merge Sort Magic |
|
Description
Because National Tsing Hua University is the number 1 university in Taiwan (citation needed) there is a lot of people that want to apply. The number of people that want to apply can be in the thousands but NTHU does not have space for all of them. Usually, the university would go through many applicant's papers but in the year of 20XX, a student suggested that the university perform an arena-based selection.
How it works is that the university will separate applicant to batches and the applicants will fight until there is only one left standing. Each applicant has their own stats (name, health, strength, magic, defense, resistance, and attack type). They will also be assigned an index.
The rules are that each applicant must attack the applicant in the next index, for example the applicant with the index 0 must attack the applicant with index 1 while the applicant with the index 22 will attack the applicant with index 23. In the scenario that there is 50 applicants, the applicant with index 49 will attack the applicant with index 0.
If a certain applicant's health is reduced to 0 or lower, they will be disqualified and they will be skipped (e.g. if the applicant at index 2 is disqualified, the applicant in index 1 will attack the applicant in index 3).
Each applicant will attack using their own attack type. If their attack type is physical then they will use their strength value to deal damage. If their attack is magical then they will use their magic value to deal damage. The applicant under attack can negate the attack values by with their defense stat for physical attacks and resistance stat for magical attacks.
The battle will go on until there is one person left standing, who will be crowned the winner and be accepted in National Tsing Hua University.
To make this idea come to fruition, a simulated prototype is made which requires 4 functions which you need to code:
1. void magicalAttack(struct Contestant* self, struct Contestant* target); (used to calculate and deal magical damage)
2. void physicalAttack(struct Contestant* self, struct Contestant* target); (used to calculate and deal magical damage)
3. void getContestants(struct Contestant* contestants, int len); (scan and create the contestant list)
4. int findTarget(struct Contestant* contestants, int idx, int len); (find the target of the current contestant)
Input
The first line contains the value of N, the number of contestants in the batch (0 <= N <= 100).
The following N lines contains 7 values for each contestant: (the contestants are already sorted based on their index)
name - health - strength - magic - defense - resistance - attack type
For the string values (name and attack type), their length will be 0 <= len <= 15
for the numerical values, their value will be 0 <= val <= 100
Output
Write down the name of the contestant followed by "wins the tournament" followed by a newline character. For example:
Bill wins the tournament
Sample Input Download
Sample Output Download
Partial Judge Code
14152.cPartial Judge Header
14152.hTags
Discuss
Description
HA! You activated my trap card! Now you must sort my cards using the merge sort algorithm.
Merge Sorting is an essential way to sort arrays. The algorithm is a 'divide and conquer' algorithm. In other words, it divides the input array into two halves, calls itself for the two halves, and then merges the two sorted halves.
The following is a pseudocode for the algorithm:
MergeSort(arr[], l, r) If r > l 1. Find the middle point to divide the array into two halves: middle m = l+ (r-l)/2 2. Call mergeSort for first half: Call mergeSort(arr, l, m) 3. Call mergeSort for second half: Call mergeSort(arr, m+1, r) 4. Merge the two halves sorted in step 2 and 3: Call merge(arr, l, m, r)
For this problem, you must write the mergesort function is already provided, so you only need to code the following function:
void merge(int*, int, int, int);
Now sort these cards or else you will be sent to the shadow realm.
Input
the first line contains the integer N (1 <= N <= 5000)
The following N lines contain the integers to be sorted. (1 <= num <= 5000)
Output
The process of the sorting (already provided by the partial judge) and the final value of the sorting.