TASK 1: Above Average Given a list of score for a class test, your program should output the number of students whose score is above the average of all the scores. Input (read from AVERAGE.IN): The first line contains an integer, N, the number of scores. 0 <= N <= 10,000 The next line contains N positive integers, the class scores. Each score is no more than 100,000. Output (write to AVERAGE.OUT): A single integer, M, the number of above-average scores, followed immediately by a new-line. AVERAGE.IN: 4 10 20 30 40 AVERAGE.OUT: 2 AVERAGE.IN: 10 40 50 55 60 55 54 70 88 49 77 AVERAGE.OUT: 4 TASK 2: Prime Factors Daniel likes 30 more than he likes 40, yet he likes 12 and 39 equally. This is because he likes numbers that have a lot of prime factors. 30 has 3 prime factors (2, 3 and 5) but 40 only has 2 (2 and 5). Both 12 and 39 have 2 prime factors (2 and 3, 3 and 13). (a prime number is a number that can be divided evenly only by itself and 1) Given a list of numbers, your program should be able to decide which of the numbers Daniel likes most. If there are a number of solutions (that he likes equally), choose the smallest. Input --- read from file PRIMES.IN First line: a single integer, N, the amount of numbers in the list. 1 <= N <= 1023 Second line: N integers, each of them is between 2 and 1024, inclusive. Output --- write to file PRIMES.OUT A single integer, B, the number Daniel likes most (or the smallest of the correct solutions) Example PRIMES.IN: 10 3 5 7 9 11 13 15 17 19 21 PRIMES.OUT 15 PRIMES.IN: 11 2 4 6 8 10 13 39 105 200 201 143 PRIMES.OUT 105 TASK 3: Strange Coins Lionel has gone on holiday to a strange, foreign land and despite his efforts, he has not yet become familiar with their local currency, which is called the ‘Olympios’. In his pocket, Lionel has N different ‘Olympios coins’. He wants to buy a present for his family in the marketplace and spots a suitable gift that costs P Olympios. He doesn’t want to use too many of his coins however, as he wants to take as many of them home with him so he can show them to his friends. He also wants to buy the gift using the exact change. Help Lionel decide if it is possible to pay for the gift using the exact change and if so, what the minimum number of coins he can use is. Input --- read from file COINS.IN The first line contains one integer, N, which is the number of coins in his pocket. 1 <= N <= 40 The next line contains one integer, P, the price of the present he wishes to purchase. 1 <= P <= 10,000 The third line contains N integers, representing the values of each of the N coins that Lionel has with him. For each coin of value C: 1 <= C <= 250 Output --- write to file COINS.OUT The output should be a single integer, K, followed immediately by a new-line. K is the minimum number of coins Lionel can use so that he can pay for the present with the exact change. If it is impossible to pay for the gift using the exact amount, use K = 0 Example: COINS.IN: 10 100 10 20 30 40 55 60 65 99 101 5 COINS.OUT: 2 (Solution: he can use 40+60) COINS.IN: 12 70 5 5 5 5 5 5 5 5 5 5 5 100 COINS.OUT: 0 (Solution: It’s not possible to pay the exact price) TASK 4: The King-Maker In the quiet banana republic of Binary, the President has been dethroned in a violent and bloody coup. One of the founders of the revolution, Michael, has been given the task of choosing the 3 people who will be the new King, civilian leader and military commander. He has agreed that he will not put himself forward for any position. He must choose wisely, as there may be trouble if the various factions (or political groups) are not satisfied with his decision. Each faction supports certain candidates to various degrees. For instance, one faction might want ‘candidate A’ to be given one of the positions, so they threaten that they will oppose the new government with 30 tanks if he is not given a position. They also say that they will support the government with 10 tanks if he IS given a position. A candidate may be endorsed by more than one faction. Michael must choose the 3 people so that the government has more tanks protecting (supporting) it than there are tanks opposed to it. You must help him choose so that the difference between the government’s tanks and the opposition tanks is maximised. If there is no way for the government to have more tanks than the opposition, then try to minimise the deficit. If there are still multiple solutions, choose the solution such that the sum of the candidates’ ID numbers is minimised. Input Line 1: a single integer, S, the number of statements made by all factions 1 <= S <= 30,000 Line 2 to Line (S+1): 3 integers: C, the ID of the candidate they want elected, J, the number of tanks they will use to oppose the government if he is not elected, K, the number of tanks they will use to support the government if he is elected. 1 <= C <= 10,000 1 <= J <= 10,000 1 <= K <= 10,000 Output Line 1: 3 integers, in ascending order, the numbers of the 3 candidates he should choose Line 2: 2 integers, the number of government tanks and the number of opposition tanks. Example KING.IN: 5 1 10 10 2 20 10 3 5 10 4 6 3 5 7 3 KING.OUT: 1 2 3 30 13 Explanation: Candidates with IDs 1, 2 and 3 should be chosen. This means that there will be 30 tanks supporting the government and 13 tanks against it. TIE-BREAK TASK: Gathering Moss Mick is a rolling stone, but ignoring the proverb, he is quite fond of gathering moss which he uses to insulate his environmentally friendly home. He likes to be very energy efficient in everything he does, not only in heating his home. Because of his obsession with efficiency, he has requested the aid of a talented young programmer like yourself to write a program for him that will aid him in his efficient collection of moss. Before he goes collecting moss, he intends to input a map of the area into your program. An example is given below: GGGGGGGGGGGGGGGG GMGMGGGGGGGGGGGG GGGGGMGGMGGGGGGG GGGGGGGGGGGGGGGG GGGGGGGGGGGGGGGG GGGGGGMGGGGGGGGG G0GGGGGGGGGGGGGG GGGGGGGGGGGGGGGG <----- Before... The ‘G’ is grass, the ‘M’ is moss and the ‘0’ is the starting location for Mick. It requires 1 unit of energy to clear a patch of grass. This particular layout of moss requires 16 units of energy to clear enough grass so that all the moss can be gathered (you can assume that gathering the moss in a square requires 1 unit of energy too). GGGGGGGGGGGGGGGG G---GGGGGGGGGGGG G-G------GGGGGGG G-GGGG-GGGGGGGGG G-GGGG-GGGGGGGGG G-GGGG-GGGGGGGGG G0GGGGGGGGGGGGGG GGGGGGGGGGGGGGGG <----- After clearing The ‘-‘ above represents a patch of cleared grass. As you can see, Mick can walk from his starting location through the cleared patches and reach all the moss. Input --- read from file MOSS.IN Line 1: an integer, M, the number of moss patches Line 2: 2 integers, X, Y, Mick’s starting location. (e.g. [1,1] is in the top left corner) Line 3 to Line (2+M): 2 integers each line, the x-y coordinate of the moss patch. Output --- write to file MOSS.OUT A single integer, E, the minimum amount of energy that needs to be used to gather the moss, followed by a newline. Example MOSS.IN: 5 27 22 42 63 93 76 MOSS.OUT: 16 MOSS.IN: 4 22 81 42 63 93 MOSS.OUT: 10 Representative map of Example 2: GGGGGGGMGGGGGGGG G0GMGGGGGGGGGGGG GGGGGMGGMGGGGGGG GGGGGGGGGGGGGGGG Solution: GGGGGGG-GGGGGGGG G0-------GGGGGGG GGGGG-GG-GGGGGGG GGGGGGGGGGGGGGGG