ZTE Plus Moon Master-Algorithmic Elite Challenge-First Pilot

1. High Jump

Difficulty: A star
Title Description:

In the new year, Niu Niu wants to jump higher. Cows themselves can jump high h h HM. At the same time Niu Niu has n n n high jump bounces, use i i i bounce makes bulls jump higher a i a_i ai meters, and the effect of the bounce is superimposable, that is, if a bull uses multiple bounces, his jump height will increase the sum of the individual effects of these bounces.

Each high jump bounce can only be used once.

Ask how many bounces bulls need to use at least to get their heights at least u u Um tall?

The data guarantees that the answer exists.

Output description:
Output an integer representing the answer.

Example:
input

3 2 5
1 3 2

output

1

Explain:
Just use the second high jump to reach 5 meters.

Questions:

import java.util.*;

public class Main {
      public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
          int n = sc.nextInt();
          int[] nums = new int[n];
              int h = sc.nextInt();
        int u = sc.nextInt();
        for (int i = 0; i < n; i++) {
            nums[i] = sc.nextInt();
        }
          
          if(u <= h){
              System.out.println(0);
              return;
          }
        Arrays.sort(nums);
        int count = 0;
        for (int i = n-1; i >= 0; i--) {
            h = h+nums[i];
            count++;
            if (h >= u){
            System.out.println(count);
            return;
            }  
        }
        System.out.println(-1);
    }   
}

2. Cutting ropes

Difficulty: A star
Title Description:
A cow has a length of n n n's rope.
On the first day, the length of the rope is n n n.
The next day, the rope will be cut into two sections of length ⌊ n 2 ⌋ \left \lfloor \frac{n}{2} \right \rfloor ⌊2n​⌋, n − ⌊ n 2 ⌋ n-\left \lfloor \frac{n}{2} \right \rfloor n−⌊2n​⌋.
On the third day, each segment cut on the next day is longer than 1 1 1 cord, set its length to m m m, the cow will cut it again
⌊ m 2 ⌋ \left \lfloor \frac{m}{2} \right \rfloor ⌊2m​⌋, m − ⌊ m 2 ⌋ m-\left \lfloor \frac{m}{2} \right \rfloor m−⌊2m​⌋.
Cut it so repeatedly...
But Niu Niu knows that one day all the ropes will be cut to {1}1, so he will have no ropes to cut. What day is it when all the ropes become {1}1 long?
Note: ⌊ n 2 ⌋ \left \lfloor \frac{n}{2} \right \rfloor _2n Representation n n n divided by 2 2 2 Round down

Enter a description:
Input contains T T T-group data, one integer in the first row T T T.
Next T T T-line with a positive integer per line n n n.

Output description:
output T T Line T, No. i i i Behavior No. i i Answers to group i data.

Example:
input

3
1
2
3

output

1
2
3

Remarks:
1 ≤ n ≤ 1 e 18 , 1 ≤ T ≤ 10000 1≤n≤1e18,1≤T≤10000 1≤n≤1e18,1≤T≤10000

Questions:

import java.util.Arrays;
import java.util.Scanner;

public class Main {
public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int T = sc.nextInt();
        long[] nums = new long[T];
        for (int i = 0; i < T; i++) {
            nums[i] = sc.nextLong();
        }

        for (long n : nums) {
            deal(n);
        }
		return;
    }

    public static void deal(long n){
        int i = 1;

        while (n > 1){
            i++;
//             n = (int)Math.max(Math.floor(n/2),n - Math.floor(n/2));
            n = Math.max(n / 2, n - n / 2);
        }
        System.out.println(i);
    }
}

3. Tasks

Difficulty: Three stars
Title Description:
Suppose we have some task lists, and the task number starts at 1. The difficulty of different tasks is also different, divided into 1-5 levels.
We are going to assign these tasks to Niu Niu, but Niu Niu is lazy. Every time he receives a task, he will find "different and numbered tasks and the five largest tasks" from his todo list, and then complete them together. Otherwise, Niu Niu will put the task in his todo list and do nothing.
Ask you to give the information about how Niu Niu completed the task according to the list of tasks you entered.
Enter a description:
The first line enters an integer n to indicate the number of tasks.
The second line, n integers separated by spaces, represents different task difficulty levels.
1\leq n \leq 10^{5}1≤n≤10
5

Output description:
Output $mathit(n) line to indicate how the cow finished each time it received a task. If a cow does nothing, it outputs -1. Otherwise, it outputs five integers, representing the five task numbers with difficulty\text 1,2,3,4,51,2,3,4,5.

Example:
input

10
1 1 2 2 3 3 4 5 4 5

output

-1
-1
-1
-1
-1
-1
-1
2 4 6 7 8
-1
1 3 5 9 10

Explain:
Output 10 lines, cattle will only complete the task when they receive the eighth and tenth tasks.

Questions:

import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        TreeMap<Integer,Queue<Integer>> map = new TreeMap<>();
        for(int i = 0;i < n;i++){
            int m = sc.nextInt();
            if(!map.containsKey(m)){
                map.put(m, new PriorityQueue<>(Comparator.reverseOrder()));
            }
            map.get(m).add(i+1);
            if(map.size() < 5){
               System.out.println(-1);
            }else{
                Iterator iterator = map.keySet().iterator();
                while(iterator.hasNext()){
                    int key = (int)iterator.next();
                    System.out.print(map.get(key).poll()+" ");
                    if(map.get(key).isEmpty()){
                        iterator.remove();
                     }
                }
                System.out.println();
            }
        }
    }
}

Keywords: Java Algorithm data structure

Added by jengle52 on Fri, 18 Feb 2022 21:52:17 +0200