A list of machine test algorithm questions in a factory

Niuke.com-HUAWEI Written Exam Interview Machine Test Online Practice

Li button to brush questions

All posts in Deco Machine Test One Star Questions

A machine test Jingle cat-Huawei machine test real questions 

GavenHwang's Blog - Huawei Machine Test

coder Mingxuan Blog-Huawei Machine Test 23 Question Summary 


Table of contents

All posts in Deco Machine Test One Star Questions

1. [Looking for children with similar height]

2. [Martian computing]

3. [The longest vowel string specifying the defect degree]

4.【Match-Match Game】

5. [Judgment string subsequence]

6. [Minimum sum of integer pairs]

7. [Reverse article fragments by interval]

8.【Longest continuous square wave signal】

9. [Array splicing]

10.【Vehicle statistics in the parking lot】

11.【The absolute value of the sum of two numbers in a sequence of out-of-order integers is the smallest】

12.【Maximum bracket depth】

13.【Print task sorting】

14.【Word Solitaire】

15. [Array deduplication and sorting]

16.【Find the smallest number】

17.【Arrange by height and weight】

18.【Pythagorean array】

19.【The absolute value of the sum of two numbers in a sequence of out-of-order integers is the smallest】

20.【Decompress message】

21.【Data Classification】

22.【Statistics of shooting competition results】

23.【Server Broadcast】

24.【Find the mode and median】

26.【The longest vowel string specifying the defect degree】

27.【we a are team[computer room]】

28. [The length of the longest sequence of non-strictly increasing consecutive numbers contained in the string]

29.【The longest continuous subsequence】

30.【Attendance information】

31.【Find the same substring】

32.【Check whether there is a number combination that meets the conditions】

33. [String filter and sort]

34. [LISP-like string operation]

35.【Output of 5-key keyboard】

36.【Memory resource allocation】

37.【Monkey Climbing a Mountain】

38.【Calculation of epidemic spread time】

39.【Calculating GPU Computing Power】

40.【String conversion minimum character string】

41.【Basketball game】

42.【Consecutive letter length】

44.【Judge whether a set of inequalities satisfy constraints and output the maximum difference】

45.【The output string contains the minimum sum of all integers】

46.【Maximum number】

47.【Looking for friends】

48.【Character statistics and rearrangement】

49.【The absolute value of the sum of two numbers in a random sequence of integers is the smallest】

50.【Texas Hold'em】

51.【Reliable car】

52.【VLAN resource pool】

53.【Task Optimal Scheduling】

54.【Find the End】

 55.【Splicing URL】

56.【Matrix maximum value】

57.【Minimum transmission delay】

58.【Efficient task planning】

59.【Maximum number of components】

60.【Area of ​​intersection of rectangles】 

61.【Implement a simple memory pool】 

62.【Factory assembly line scheduling】

63.【Express Transportation】

64.【Delete directory】

 65.【Task scheduling problem】

66.【English input method word association】

67.【Solving continuous series】

68.【Interval Intersection】

69.【A Master of Cards】

70. [Sort the logs according to the order of the log time]

71.【Moon cakes】

71.【Sliding window maximum value】

72.【Wave Array Finding Alphabet Game】

73.【The smallest number】

74.【Deciphering the crime time】

75.【Task Optimal Scheduling】

76.【Maximum value】

77.【Arranging by height and weight】

78.【Looking for children with similar height】

79.【Binary tree inorder traversal output】 

80.【kth permutation】

81.【Find the sum of the largest n numbers and the smallest n numbers in the array】

82.【Rearrangement of times of shouting 7】

83.【Arrays are used to store binary trees】

84.【Maximum Submatrix Sum】

85.【Sorting by disk capacity】

86.【Decompression of a string compressed representation】

87.【Maximum spending amount】

88.【The Farthest Footprint】

89.【Calculation area】

 90.【Maximum Matrix Sum】

91.【The longest broadcast response】

92.【Breadth-first traversal of binary tree】

93.【Find the minimum sum of all integers in a string】

94.【Seek the maximum number of teams that can be dispatched】

95.【Number reverse printing】

 96【Hot Pot】

97.【Looking for a parking space】

98.【Sensitive field encryption】

99.【String Statistics】 

 100.【Jiugongge button】

 101.【Counting Game】

102.【Stacking blocks】

103.【What to do if the job number is not enough】

 104.【Number of squares formed】

105.【The longest continuous subsequence】

 106.【Minimum number of exchanges according to a certain condition】

107.【Jumping grid game】

108.【MVP Battle】

109.【The location of the school】

110.【Assemble a new array】


1. [Looking for children with similar height]

[Looking for children with similar heights] Xiao Ming entered the first grade of elementary school this year. After coming to the new class, he found that other children were of uneven heights, and then wanted to sort them based on the height difference between the children and himself. Please help him realize the sorting .

Enter a description:

The first row is positive integers H and N, 0<H<200, is the height of Xiao Ming, 0<N<50, is the number of other children in the new class. The second row is N positive integers H1-HN, which are the heights of other children, and the value range is 0<N<50, which is the number of other children in the new class. The second line is N positive integers H1-HN, which are the heights of other children, and the value range is 0><Hi<200 (1<=i<=N), and the N positive integers are different.

Output description:

Output the sorting results, each positive integer is separated by a space. The child with the smallest absolute value of height difference with Xiao Ming is ranked first, and the child with the largest absolute value of height difference with Xiao Ming is ranked last. If the height difference between the two children and Xiao Ming is the same, the smaller child is ranked first.

Example 1:

enter

100 10

95 96 97 98 99101 102 103 104 105           

output

99 101 98 102 97103 96 104 95 105

2. [Martian computing]

[Martian Calculation] It is known that the operators used by Martians are # and $, and their equivalent formulas with those on Earth are as follows:

x#y = 2x+3y+4

x$y = 3*x+y+2

Among them, x and y are unsigned integers.
The Earthman formula is calculated according to the C language rules
. In the Martian formula, $ has a higher priority than #. The same operator calculates the existing Martian string in order from left to right. Message, please translate and calculate the result.
Enter a description:

Martian string expression (without carriage return and line feed at the end)
**Input string description: **

Strings are composed only of unsigned integers and operators (#, $)

Composed calculation expressions. For example: 123#45#6778

The use case guarantees that there are no separators between operands and operators in the string.
The use case guarantees that the value range of the operand is a 32-bit unsigned integer.
Guaranteed that the input and the calculation result will not have integer overflow.
Ensure that the input string is a legal evaluation message, for example: 123#45#6778
Ensure that there will be no illegal evaluation message, such as a string like this:
#4$5 //Missing operand
4$5# // Missing operand
4#$5 //Lacking operand
4 $5 //There is space
3+4-5*6/7 //There are other operators
12345678987654321$54321 //32-bit integer calculation overflow
Output description:

Output calculation results according to the input Martian string (without carriage return and line feed at the end)

example

enter:

7#6$5#12
output:

226
instructions:

7#6$5#12=7#(3*6+5+2)#12
=7#25#12
=(2*7+3*25+4)#12
=93#12
=2*93+3*12+4
=226


3. [The longest vowel string specifying the defect degree]

[The longest vowel string with a specified flaw degree] The longest vowel substring with a specified flaw degree | Time limit: 1 second | Memory limit: 262144K | Language limit: Any vowel at the beginning and end (
aeiouAEIOU ) is a vowel string, and the number of mixed non-vowel letters is its defect degree. For example:
"a" and "aa" are vowel strings, and their flaws are both 0

· "aiur" is not a vowel string (ends without a vowel character)

· "abira" is a vowel string with a flaw degree of 2

Given a string, please find the longest vowel substring with the specified defect degree, and output its length, if no vowel substring satisfying the condition is found, output 0.

Substring: A subsequence composed of any consecutive characters in a string is called a substring of the string.

Collapse
Input description:
The input in the first line is an integer, indicating the expected flaw degree flaw, and the value range is [0, 65535].
The next line is a string consisting of only characters az and AZ, the string length is (0, 65535].
Output description:
The output is an integer, representing the length of the vowel character substring that meets the condition.

Example 1
Input
0
asdbuiodevauufgh
Output
3
Explanation
There are two longest vowel character substrings that meet the conditions, namely uio and auu, and the length is 3.

Example 2
Input
2
aeueo
and output
0
means
there is no vowel character substring that meets the condition, output 0
Example 3
Input
1
aabeebuu
Output
5
indicates that
there are two longest vowel character substrings that meet the condition, namely aabee and eebuu, and the length is 5

4.【Match-Match Game】

[Miscellaneous Game] Game rules: Enter a string containing only English letters, and if two letters in the string are adjacent and identical, they can be eliminated.

Repeat the elimination action on the string until the elimination cannot continue, and the game is over at this time.

Output the resulting string length.

5. [Judgment string subsequence]

【Judging string subsequence】Given the string target and source, judge whether target is a subsequence of source. You can think that target and source only contain English lowercase letters, the string source may be very long, the length is ~=500,000, and target is a short string, the length is <=100. A subsequence of a string is a new string formed by deleting some (or none) characters from the original string without changing the relative positions of the remaining characters, for example, 'abc' is a subsequence of 'aebycd', and 'ayb' no. Please find the starting position of the last sequence.
Example input:
abc
abcaybec
example output:
3
because a of abc in aybec has a position index of 3 in the entire string

6. [Minimum sum of integer pairs]

[Minimum sum of integer pairs] Given two integer arrays array1 and array2, the array elements are arranged in ascending order. Assuming that taking one element from array1 and array2 respectively can form a pair of elements, now it is necessary to take out k pairs of elements, sum all the taken elements, and calculate the minimum value of the sum.
Note: If two pairs of elements correspond to the same two subscripts in array1 and array2, they are regarded as the same pair of elements.

Input description
Input two lines of array array1, array2, the first number of each line is the size of the array size(0<size<=100)
0<array1[i]<=1000
0<array2[i]<=1000
The next line is positive integer k
0<k<=array1.size()*array2.size()

输出描述
满足要求的最小和

示例1

输入
3 1 1 2
3 1 2 3
2
输出
4

7.【按区间反转文章片段】

题目描述:

输入一个英文文章片段,翻转指定区间的单词顺序,标点符号和普通字母一样处理。
例如输入字符串 “I am a developer.”,区间[0,3]则输出 “developer. a am I”。
输入描述:

使用换行隔开三个参数
第一个参数为英文文章内容即英文字符串
第二个参数为反转起始单词下标,下标从0开始
第三个参数为结束单词下标,
输出描述:

反转后的英文文章片段,所有单词之间以一个半角空格分割进行输出

示例

输入:

I am a developer.

1

2

输出:

I a am developer.
输入:

Hello world!
0
1
输出:

world! Hello
说明:

输入字符串可以在前面或者后面包含多余的空格,但是反转后的不能包含多余空格。
输入:

I am a developer.
0
3
输出:

developer. a am I
说明:

如果两个单词见有多余的空格,将反转后单词间的空格减少到只含一个。
输入:

Hello!
0
3
输出:

EMPTY
说明:

指定反转区间只有一个单词,或无有效单词则统一输出EMPTY。

8.【最长方连续方波信号】

[Longest continuous square wave signal] Longest continuous square wave signal | Time limit: 1 second | Memory limit: 262144K | Language limit: Unlimited
Input a series of square wave signals to find the longest completely continuous alternating square wave signal, and output it. If there are alternating square wave signals of the same length, you can output any one. The high bit of the square wave signal is marked with 1, and the low bit is marked with 0, as shown in the figure: Explanation: 1) A complete signal must be marked
with
0 It starts and ends with 0, that is, 010 is a complete signal, but 101, 1010, 0101 are not
2) A series of square wave signals input is composed of one or more complete signals
3) There may be 0 between two adjacent signals One or more low bits, such as 0110010, 011000010
4) There can be continuous high bits in the same signal, such as 01110101011110001010, the first 14 bits are a signal with continuous high bits
5) Completely continuous alternating square wave refers to 10 alternating, such as 01010 is Completely continuous alternating square wave, 0110 is not
 input Description: Input signal string (length >=3 and <=1024): 0010101010110000101000010 Note: Input is always legal, regardless of abnormal conditions Output description: Output the longest completely continuous alternating square
wave Wave signal string: 01010 If there is no completely continuous alternating square wave signal string, output -1


示例1
输入
00101010101100001010010
输出
01010
备注:
输入信号串中有三个信号:0 010101010110(第一个信号段) 00 01010(第二个信号段) 010(第三个信号段)
第一个信号虽然有交替的方波信号段,但出现了11部分的连续高位,不算完全连续交替方波,在剩下的连续方波信号串中01010最长

9. [Array splicing]

Now there are multiple sets of integer arrays that need to be merged into a new array
merging rule. The content of a fixed length is taken out from each array in order and merged into a new array. The content that has been taken will be deleted. Or it is already empty, then directly take out the rest of the content and put it in a new array to continue to the next line

Input description
  The first line is the fixed length of each read.
  Length 0<len<10
  The second line is the number of integer
  arrays 0<num<10000
  The third to n lines are the arrays that need to be merged.
  Different arrays are separated by newlines
  . Use commas to separate
  the maximum of 100 elements

 Output Description
  Output a new array, separated by commas

  Example 1
  Input
      3
      2
      2,5,6,7,9,5,7
      1,7,4,3,4
  Output
      2,5,6,1,7,4,7,9,5,3,4, 7

  Explanation To obtain the length 3 and the number of arrays 2,
     first traverse the first row to obtain 2, 5, 6,
     then traverse the second row to obtain 1, 7, 4,
     then loop back to the first row to obtain 7, 9, 5,
     and then traverse the second row to obtain 3 ,4
     go back to the first row to get 7

  Example 2
  input
     4
     3
     1,2,3,4,5,6
     1,2,3
     1,2,3,4
   output
     1,2,3,4,1,2,3,1,2,3,4 ,5,6

10.【Vehicle statistics in the parking lot】

题目描述:
特定大小的停车场,数组cars[]表示,其中1表示有车,0表示没车。
车辆大小不一,小车占一个车位(长度1),货车占两个车位(长度2),卡车占三个车位(长度3)。
统计停车场最少可以停多少辆车,返回具体的数目。
输入描述:
整型字符串数组cars[],其中1表示有车,0表示没车,数组长度小于1000。

输出描述:
整型数字字符串,表示最少停车数目。

示例 1:

输入
1,0,1
输出
2
说明
1个小车占第1个车位
第二个车位空
1个小车占第3个车位
最少有两辆车
示例 2:

输入
1,1,0,0,1,1,1,0,1
输出
3
说明
1个货车占第1、2个车位
第3、4个车位空
1个卡车占第5、6、7个车位
第8个车位空
1个小车占第9个车位
最少3辆车

11.【乱序整数序列两数之和绝对值最小】

标题:乱序整数序列两数之和绝对值最小 | 时间限制:1秒 | 内存限制:262144K | 语言限制:不限

Given a random integer (there may be positive and negative integers) array nums, please find two numbers in the array whose absolute value (|nums[x]+nums[y]|) is the smallest value, and returns the two numbers (returned in ascending order) and the absolute value.
Each input will only correspond to one answer. However, the same element in the array cannot be used twice.

Enter a description:

An ordered integer sequence string separated by spaces, up to 1000 integers, and the value range of integers is [-65535, 65535].

Output description:

The minimum absolute value of the sum of two numbers
Example 1

enter

-1 -3 7 5 11 15

output

-3 5 2

illustrate

Because |nums[0] + nums[2]| = |-3 + 5| = 2 is the smallest, so return -3 5 2

12.【Maximum bracket depth】

Existing string only consists of ( , ) , { , } , [ , ] six kinds of brackets. If the string meets one of the following conditions, it is an invalid string:
1. The number of left and right brackets of any type is not equal;
2. There are brackets that are not closed in the correct order (left first, then right).

Output the maximum nesting depth of brackets, if the string is invalid, output 0.
0<=string length<=100000

Input description:
a string containing only ( , ) , { , } , [ , ].

Output description:
an integer, the maximum bracket depth

Example 1:
Input: []
Output: 1


13.【Print task sorting】

题目描述
某个打印机根据打印队列执行打印任务。打印任务分为九个优先级,分别采用数字1~9表示,数字越大优先级越高。打印机每次从队列头部取出第一个任务A,然后检查队列余下任务中有没有比A优先级更高的任务,如果有比A优先级高的任务,则将任务A放到队列尾部,否则执行任务A的打印。请编写一个程序,根据输入的打印队列,输出实际打印顺序。

输入描述
函数原型:
void printOrder(const int input[], int len, int output[])
参数input表示打印队列,为1~9(优先级)组成的数组,数组索引0代表头部。对于C/C++参数len代表input数组长度,假定参数合法有效;

14.【单词接龙】

题目描述:

单词接龙的规则是:

用于接龙的单词首字母必须要前一个单词的尾字母相同;
当存在多个首字母相同的单词时,取长度最长的单词,如果长度也相等,则取字典序最小的单词;
已经参与接龙的单词不能重复使用。
现给定一组全部由小写字母组成单词数组,并指定其中的一个单词作为起始单词,进行单词接龙。

请输出最长的单词串,单词串是单词拼接而成,中间没有空格。

输入描述:

输入的第一行为一个非负整数,表示起始单词在数组中的索引K,0 <= K < N。
输入的第二行为一个非负整数,表示单词的个数N。
接下来的N行,分别表示单词数组中的单词。
输出描述:

输出一个字符串,表示最终拼接的单词串。
备注:

单词个数N的取值范围为[1, 20]
单个单词的长度的取值范围为[1, 30]

15.【数组去重和排序】

Topic description:
Given a random array, delete all duplicate elements so that each element appears only once, and sort according to the number of occurrences from high to low, and sort the same number of occurrences in the order of first appearance.

Input description:
an array

Output description:
the array after de-reordering

Example 1:
Input
1,3,3,3,2,4,4,4,5
1
Output
3,4,1,2,5
1
Note
The size of the array does not exceed 100 The size of the array element value does not exceed 100

16.【Find the smallest number】

Title description:

Given a positive integer num1, calculate a new positive integer num2. num2 is the result of removing N digits from num1. It is necessary to minimize the value of num2. Input: 1. The first
line
of input is a string consisting of 0- Composed of 9 characters, record positive integer num1, the length of num1 is less than 32
2. The second input line is the number of numbers to be removed, which is less than the length of num1
Example

10
1
output 0
10200
1
output 200
2615371
4
output 131


17.【Arrange by height and weight】

Title description:

A school held a sports meeting, and the students were identified by numbers (1, 2, 3...n). Now it is necessary to arrange them according to their height from low to high. For people with the same height, they should be arranged according to their weight from light to heavy. For those with the same height and weight Person, maintain the original numbering sequence relationship.
Please output the sorted student number
Enter description:

Two sequences, each sequence consists of N positive integers, (0<n<=100).
The values ​​in the first sequence represent height and
the values ​​in the second sequence represent weight
Output description:

Arrange the results, each value is the student number in the original sequence, the number starts from 1, the height is from low to high, the height is the same and the weight is from light to heavy, and the weight is the same to maintain the original order.
Example:

enter:

4
100 100 120 130
40 30 60 50
output:

2134
input:

3
90 110 90
45 60 45
output:

132


18.【Pythagorean array】

Title description:

If there are three positive integers ABC, A²+B²=C², it is a Pythagorean number.
If ABC is mutually prime, that is, A, BA, CB, and C are all mutually prime and have no common divisor,
then it is called a Pythagorean number tuple. .
Request all Pythagorean number tuples within a given nm range
Input description
Start range 1<n<10000 n<m<10000
Output item description
abc Guaranteed a<b<c output format abc
multiple groups of Pythagorean number tuples according to aAscending bAscending cAscending sorting output.
If no Pythagorean tuple is found within the given range, output Na

Case 1
 Input
  1
  20
  Output
   3 4 5
   5 12 13
   8 15 17

Case 2:
  Input
    5
    10
  output
    Na

19.【The absolute value of the sum of two numbers in a sequence of out-of-order integers is the smallest】

Title description:

Time limit: 1 second | Memory limit: 262144K 

Given a random integer (there may be positive and negative integers) array nums, please find two numbers in the array whose absolute value (|nums[x]+nums[y]|) is the smallest value, and returns the two numbers (returned in ascending order) and the absolute value.
Each input will only correspond to one answer. However, the same element in the array cannot be used twice.

Enter a description:

An ordered integer sequence string separated by spaces, up to 1000 integers, and the value range of integers is [-65535, 65535].

Output description:

The minimum absolute value of the sum of two numbers

Example 1

enter

-1 -3 7 5 11 15

output

-3 5 2

illustrate

Because |nums[0] + nums[2]| = |-3 + 5| = 2 is the smallest, so return -3 5 2

20.【Decompress message】

题目描述:
解压报文 | 时间限制:1秒 | 内存限制:262144K | 语言限制:不限
为了提升数据传输的效率,会对传输的报文进行压缩处理。输入一个压缩后的报文,请返回它解压后的原始报文。
压缩规则:n[str],表示方括号内部的 str 正好重复 n 次。注意 n 为正整数(0 < n <= 100),str只包含小写英文字母,不考虑异常情况。
" “输入描述:
输入压缩后的报文:
1)不考虑无效的输入,报文没有额外的空格,方括号总是符合格式要求的;
2)原始报文不包含数字,所有的数字只表示重复的次数 n ,例如不会出现像 5b 或 3[8] 的输入;
输出描述:
解压后的原始报文
注:
1)原始报文长度不会超过1000,不考虑异常的情况
示例1
输入
3[k]2[mn]
输出
kkkmnmn
说明
k 重复3次,mn 重复2次,最终得到 kkkmnmn
示例2
输入
3[m2[c]]
输出
mccmccmcc
说明
m2[c] 解压缩后为 mcc,重复三次为 mccmccmcc”

21.【数据分类】

To classify a data a, the classification method is: add the four bytes of this data a (size of four bytes) to % a given value b, if the obtained result is less than a given value c, then this The result is the type of data a; if the obtained result is greater than or equal to c, the invalid result means that the type of data a is invalid. For example, a data a=0x01010101, b=3, calculated according to the classification method (0x01+0x01+0x01+0x01)%3=1, so if c=2, then the type of a is 1, if c=1, then this The type of a is invalid. Input 12 data, the first data is c, the second data is b, and the remaining 10 data are data a to be classified. Calculate how many data there are in the type with the most data (effective type).
Input description:
Input 12 data, the first data is c, the second data is b, and the remaining 10 data are data a that needs to be classified.
Output description:
Calculate how many data are in the type (valid type) with the most data.
Example 1
Input
5, 2, 1, 2, 3 , 4, 5, 6, 7, 8, 9, 10
Output
5

22.【Statistics of shooting competition results】

Title description
Given a shooting competition transcript, which contains the scores of several shots by multiple players, please rank each player in descending order according to the sum of their highest 3 scores, and output the ID sequence of the players ranked in descending order.

The conditions are as follows:

A player can have multiple marks for shooting performance, and the order is not fixed.
If a player has less than 3 scores, all the scores of the player will be considered invalid, and the player will be ignored in the ranking.
If the sum of the scores of the players is equal, the players with equal sums of scores are sorted in descending order of their IDs.
Enter a description:

Enter the first line, an integer N, indicating that a total of N shots were taken in the game, and N scores were generated (2<=N<=100).
Enter the second line, an integer sequence of length N, representing the ID of the player participating in each shooting (0<=ID<=99).
Enter the third line, an integer sequence of length N, indicating the corresponding score of the players participating in each shooting (0<=score<=100).
Output description:
The sequence of player IDs ranked in descending order that meets the conditions set in the question.

Example 1
input

13
3,3,7,4,4,4,4,7,7,3,5,5,5
53,80,68,24,39,76,66,16,100,55,53,80,55

output

5,3,7,4

illustrate

The shooting competition was carried out 13 times, and the participating players were {3, 4, 5, 7}. Player No. 3 scores:
53, 80, 55, the sum of the highest 3 scores is: 80+55+53=188.
Player No. 4 scores: 24, 39, 76, 66, the sum of the highest 3 scores is: 76+66+39=181.
Player No. 5 scores: 53, 80, 55, the sum of the highest 3 scores is: 80+55+53=188.
Player No. 7 scores: 68, 16, 100, the sum of the highest 3 scores is: 100+68+16=184.
Comparing the sum of the highest 3 results of each player, there is No. 3 = No. 5 > No. 7 > No. 4. Since No. 3 and No. 5 have the same results and ID No. 5>3, the output is: 5, 3, 7, 4

23.【Server Broadcast】

题目:服务器连接方式包括直接相连,间接连接。 A 和 B 直接连接, B 和 c 直接连接,则 A 和 c 间接连接。直接连接和间接连接都可以发送广播。
给出一个 N * N 数组,代表 N 个服务器, matrix[i][j] == 1 ,则代表 i 和 j 直接连接;不等于 1 时,代表 i 和 j 不直接连接。 matrix[i][i]== 1 ,即自己和自己直接连接。 matrix[i][j]==matrix[j][i] 。计算初始需要给几台服务器广播,才可以使侮个服务器都收到广播。
输入描述: n * n 矩阵,

[[1,1,0],[1,1,0],[0,0,1]]
1
输出描述:整数

2

24.【查找众数及中位数】

题目描述:
1.众数是指一组数据中出现次数量多的那个数,众数可以是多个
2.中位数是指把一组数据从小到大排列,最中间的那个数,如果这组数据的个数是奇数,那最中间那个就是中位数,
如果这组数据的个数为偶数,那就把中间的两个数之和除以 2,所得的结果就是中位数
3.查找整型数组中元素的众数并组成一个新的数组,求新数组的中位数
输入描述:
输入一个一维整型数组,数组大小取值范围 0 < N < 1000,数组中每个元素取值范围 0 < E < 1000
输出描述:
输出众数组成的新数组的中位数
示例 1:
输入
10 11 21 19 21 17 21 16 21 18 15
输出
21
25.【分糖果】

题目描述:

小明从糖果盒中随意抓一把糖果 每次小明会取出一半的糖果分给同学们 当糖果不能平均分配时 小明可以从糖果盒中(假设盒中糖果足够)取出一个或放回一个糖果 小明至少需要多少次(取出放回和平均分配均记一次)能将手中糖果分至只剩一颗

示例: 输入 :15 输出: 5 输入 :4 输出:2

26.【最长的指定瑕疵度的元音字串】

题目描述:

最长的指定瑕疵度的元音子串 | 时间限制:1秒 | 内存限制:262144K | 语言限制:不限
开头和结尾都是元音字母(aeiouAEIOU)的字符串为 元音字符串 ,其中混杂的非元音字母数量为其 瑕疵度 。比如:
· “a” 、 “aa”是元音字符串,其瑕疵度都为0

· “aiur”不是元音字符串(结尾不是元音字符)

· "abira" is a vowel string with a flaw degree of 2

Given a string, please find the longest vowel substring with the specified defect degree, and output its length, if no vowel substring satisfying the condition is found, output 0.

Substring: A subsequence composed of any consecutive characters in a string is called a substring of the string.

Collapse
Input description:
The input in the first line is an integer, indicating the expected flaw degree flaw, and the value range is [0, 65535].
The next line is a string consisting of only characters az and AZ, the string length is (0, 65535].
Output description:
The output is an integer, representing the length of the vowel character substring that meets the condition.

Example 1
Input
0
asdbuiodevauufgh
Output
3
Explanation
There are two longest vowel character substrings that meet the conditions, namely uio and auu, and the length is 3.

Example 2
Input
2
aeueo
and output
0
means
there is no vowel character substring that meets the condition, output 0
Example 3
Input
1
aabeebuu
Output
5
indicates that
there are two longest vowel character substrings that meet the condition, namely aabee and eebuu, and the length is 5

27.【we a are team[computer room]】

Title description:

总共有n个人在机房,每个人有一个标号(1<=标号<=n),他们分成了多个团队,需要你根据收到的m条消息判定指定的两个人是否在一个团队中,具体的:
1、消息构成为a b c,整数a、b分别代表两个人的标号,整数c代表指令
2、c == 0代表a和b在一个团队内
3、c == 1代表需要判定a和b的关系,如果a和b是一个团队,输出一行'we are a team',如果不是,输出一行'we are not a team'
4、c为其他值,或当前行a或b超出1~n的范围,输出‘da pian zi'
输入描述:
1、第一行包含两个整数n,m(1<=n,m<100000),分别表示有n个人和m条消息
2、随后的m行,每行一条消息,消息格式为:a b c(1<=a,b<=n,0<=c<=1)
输出描述:
1、c ==1,根据a和b是否在一个团队中输出一行字符串,在一个团队中输出‘we are a team',不在一个团队中输出'we are not a team’
2、c为其他值,或当前行a或b的标号小于1或者大于n时,输出字符串‘da pian zi'
3、如果第一行n和m的值超出约定的范围时,输出字符串'Null'
输入:
5 7
1 2 0
4 5 0
2 3 0
1 2 1
2 3 1
4 5 1
1 5 1
输出:
We are a team
We are a team
We are a team
We are not a team
输入:
5 6
1 2 0
1 2 1
1 5 0
2 3 1
2 5 1
1 3 2
输出:
we are a team
we are not a team
we are a team
da pian zi

28. [The length of the longest sequence of non-strictly increasing consecutive numbers contained in the string]

Title description:

Input a string containing only uppercase and lowercase letters and numbers Find
the length of the longest non-strictly increasing continuous number sequence contained in the string
For example:
    12234 belongs to the non-strictly increasing number sequence
Example:
input
    abc2234019A334bc
Output
    4
description:
    2234 is the longest non-strictly increasing sequence of numbers Strictly increasing sequence of consecutive numbers, so length 4

    aaaaaa44ko543j123j7345677781
    aaaaa34567778a44ko543j123j71
    345678a44ko543j123j7134567778aa

29.【The longest continuous subsequence】

Title description:

There is a sequence composed of N positive integers.
Given an integer sum,
find the longest continuous subsequence so that their sum is equal to
the length of the subsequence returned by sum
. Return -1 if there is no sequence that meets the requirements.
Case 1:
Input
1, 2,3,4,2
6
Output
3
Analysis: Both sequences 1,2,3 and 4,2 can meet the requirements
, so the longest continuous sequence is 1,2,3, so the result is 3

30.【Attendance information】

Title description:

The company uses a string to represent employee attendance information:

absent: absence

late: late

leaveearly: leaving early

present: go to work normally

Now it is necessary to judge whether the attendance award can be obtained according to the employee's attendance information. The conditions for obtaining the attendance award are as follows:

No more than one absence; no consecutive lateness/early leave; any 7 consecutive attendances, no more than 3 absences/lateness/early leave

present

present absent present present leaveearly present absent

Output description:

According to the attendance data string, if the attendance reward can be obtained, output "true"; otherwise output "false", the result of the input example should be:

true false

31.【Find the same substring】

Title description:

Given you two strings t and p,
it is required to find a continuous substring from t that is the same as p, and output the subscript of the first character of the substring Input
description:

The input file includes two lines representing the strings t and p, respectively.
Ensure that the length of t is not less than p
and the length of t does not exceed 1000000.
The length of p does not exceed 10000.
Output description:

如果能从t中找到一个和p相等的连续子串
则输出该子串第一个字符在t中的下标
下标从左到右依次为1,2,3,…;
如果不能,则输出 “No”
如果含有多个这样的子串,则输出第一个字符下标最小的
示例

输入:

AVERDXIVYERDIAN
RDXI
输出:

4

32.【检查是否存在满足条件的数字组合】

给定一个正整数数组 检查数组中是否存在满足规则的数组组合 规则: A=B+2C

输入描述 第一行输出数组的元素个数 接下来一行输出所有数组元素 用空格隔开

输出描述 如果存在满足要求的数 在同一行里依次输出 规则里 A/B/C的取值 用空格隔开 如果不存在输出0

示例1: 输入 4 2 7 3 0 输出 7 3 2 说明: 7=3+2*2

示例2: 输入 3 1 1 1 输出 0 说明找不到满足条件的组合

备注: 数组长度在3~100之间 数组成员为0~65535 数组成员可以重复 但每个成员只能在结果算式中使用一次 如 数组成员为 [0,0,1,5] 0出现两次允许,但结果0=0+2*0不允许 因为算式中使用了3个0 用例保证每组数字里最多只有一组符合要求的解

33.【字符串筛选排序】

题目描述:
输入一个由 n 个大小写字母组成的字符串,按照 Ascii 码值从小到大的排序规则,查找字符串中第 k 个最小
ascii 码值的字母(k >= 1),输出该字母所在字符串的位置索引(字符串的第一个字符位置索引为 0)。
k 如果大于字符串长度,则输出最大 ascii 值的字母所在字符串的位置索引,如果有重复的字母,则输出字母的最小位置索引。
输入描述:
第一行输入一个由大小写字母组成的字符串
第二行输入 k,k 必须大于 0,k 可以大于输入字符串的长度
输出描述:
输出字符串中第 k 个最小 ascii 码值的字母所在字符串的位置索引。k 如果大于字符串长度,则输出最大 ascii 值的字母所
在字符串的位置索引,如果第 k 个最小 ascii 码
值的字母存在重复,则输出该字母的最小位置索引。
示例 1:
输入
AbCdeFG
3
输出
5

34.【仿LISP字符串运算】

题目描述
LISP语言唯一的语法就是括号要配对。
形如 (OP P1 P2 …),括号内元素由单个空格分割。
其中第一个元素OP为操作符,后续元素均为其参数,参数个数取决于操作符类型
注意:参数 P1, P2 也有可能是另外一个嵌套的 (OP P1 P2 …)
当前OP类型为add/sub/mul/div(全小写),分别代表整数的加减乘除法。简单起见,所以OP参数个数为2
举例
-输入:(mul 3 -7)输出:-21
输入:(add 1 2) 输出:3
输入:(sub (mul 2 4) (div 9 3)) 输出 :5
输入:(div 1 0) 输出:error
常规方法是用两个栈分别存放操作数和操作符,本文用一个栈来实现,首先从后往前提取操作数和操作符存放在vector,然后判断

35.【5键键盘的输出】

题目描述:

有一个特殊的五键键盘,上面有A、Ctrl-C、Ctrl-X、Ctrl-V、Ctrl-A A键在屏幕上输出一个字母A,Ctrl-C将当前所选的字母复制到剪贴板,Ctrl-X将当前选择的字母复制到剪贴板并清空所选择的字母,Ctrl-V将当前剪贴板的字母输出到屏幕,Ctrl-A选择当前屏幕中所有字母
条件如下:

The clipboard is initially empty.
Copying new content to the clipboard will overwrite the original content
. When there is no letter on the screen, Ctrl-A is invalid.
When no letter is selected, Ctrl-C and Ctrl-X are invalid.
When a letter is selected, A and Ctrl are invalid. The keys of the two output functions -V will clear the selected letters first and then output.
Given a series of keyboard inputs, output the number of letters on the final screen
. Input description:

The input is one line
. To simplify the analysis, the number 12345 is used to replace the input of A, Ctrl-C, Ctrl-X, Ctrl-V, and Ctrl-A. The
numbers are separated by spaces
. Output description:

Output a number as the total number of letters on the screen
Example 1

enter:

1 1 1
output:

3
example two

enter:

1 1 5 1 5 2 4 4
output:

2

36.【Memory resource allocation】

Title description:

There is a simple memory pool. The memory is classified according to size and granularity. Each granularity has a number of available memory resources. Users will apply for a series of memory and need to allocate resources in the memory pool as needed, and return a list of successful and failed applications.
The allocation rules are as follows:
the allocated memory must be greater than or equal to the amount of memory requested. If there is memory that meets the demand, it must be allocated. Priority is given to allocation of small granularity, but the memory cannot be split for use.
It needs to be allocated in order of application, and those who apply first will be allocated first.
If there is available memory allocation, the application result is true, and if there is no available memory allocation, it returns false.
Note: memory release is not considered.

Enter a description:

The first line is the list of memory pool resources, including the memory granularity data information. The granularity data is separated by commas, and the internal granularity information is separated by colons. Before the colon is the size of the memory granularity, and after the colon is the quantity. The resource list is not greater than 1024, and the number of each granularity is not greater than 4096.

第二行为申请列表,申请的内存大小间用逗号分隔。申请列表不大于100000。

如:

64:2,128:1,32:4,1:128
50,36,64,128,127
1
2
输出描述:

输出为内存池分配结果。

如:

true,true,true,false,false
1
示例

输入:

64:2,128:1,32:4,1:128
50,36,64,128,127
1
2
输出:

true,true,true,false,false
1
说明:

内存池资源包含:64K共2个、128K共1个、32K共4个、1K共128个的内存资源;

针对50,36,64,128,127的内存申请序列,分配的内存依次是:64,64,128,NULL,NULL,

第三次申请内存时已经将128分配出去,因此输出结果是:

true,true,true,false,false

37.【猴子爬山】

天一只顽猴想要从山脚爬到山顶
  途中经过一个有n个台阶的阶梯,但是这个猴子有个习惯,每一次只跳1步或3步
  试问?猴子通过这个阶梯有多少种不同的跳跃方式

  输入描述:
    输入只有一个这个数n    0<n<50
    此阶梯有多个台阶
  输出描述:
    有多少种跳跃方式

  实例:
   输入
     50
   输出
      122106097

   输入
      3
   输出
      2

38.【计算疫情扩散时间】

计算疫情扩散时间 | 时间限制:1秒 | 内存限制:32768K | 语言限制:不限
在一个地图中(地图由n*n个区域组成),有部分区域被感染病菌。感染区域每天都会把周围(上下左右)的4个区域感染。
请根据给定的地图计算,多少天以后,全部区域都会被感染。

如果初始地图上所有区域全部都被感染,或者没有被感染区域,返回-1
收起
输入描述:
一行N*N个数字(只包含0,1,不会有其他数字)表示一个地图,数字间用,分割,0表示未感染区域,1表示已经感染区域
每N个数字表示地图中一行,输入数据共表示N行N列的区域地图。
例如输入1,0,1,0,0,0,1,0,1,表示地图
1,0,1
0,0,0
1,0,1
输出描述:
一个整数,表示经过多少天以后,全部区域都被感染
示例1
输入
1,0,1,0,0,0,1,0,1
输出
2
说明
1天以后,地图中仅剩余中心点未被感染;2天以后,全部被感染。
示例2
输入
0,0,0,0
输出
-1
说明
无感染区域
示例3
输入
1,1,1,1,1,1,1,1,1
输出
-1
说明
全部都感染
备注:
1<=N<200

39.【计算GPU算力】

为了充分发挥Gpu算力,
 需要尽可能多的将任务交给GPU执行,
 现在有一个任务数组,
 数组元素表示在这1s内新增的任务个数,
 且每秒都有新增任务,
 假设GPU最多一次执行n个任务,
 一次执行耗时1s,
 在保证Gpu不空闲的情况下,最少需要多长时间执行完成。

 输入描述
   第一个参数为gpu最多执行的任务个数
   取值范围1~10000
   第二个参数为任务数组的长度
   取值范围1~10000
   第三个参数为任务数组
   数字范围1~10000

 输出描述
   执行完所有任务需要多少秒

 例子
   输入
    3
    5
    1 2 3 4 5
   输出
    6

    说明,一次最多执行3个任务  最少耗时6s

  例子2
    输入
     4
     5
     5 4 1 1 1
    输出
     5

   说明,一次最多执行4个任务  最少耗时5s

40.【字符串变换最小字符串】

题目描述:

Given a string s, at most one transformation can be performed, and the smallest string that can be obtained after transformation is returned (compared according to lexicographical order).
Transformation rules: Exchange any two characters in different positions in a string.
Enter a description:

A string s composed of a string of lowercase letters
outputs a description:

The minimum string obtained by transforming as required Remarks
:

s is composed of lowercase characters
1<=s.length<=1000
example

enter:

abcdef
output:

abcdef
description:

abcdef is already the minimum string, no need to swap
Input:

bcdefa
output:

acdefb
Description:

The positions of a and b are exchanged to get the smallest string

41.【Basketball game】

In a basketball (5V5) game, each player has a combat power, and the sum of the combat power of all players in each team is the team's overall combat power. There are currently 10 players who are going to be divided into two teams for a training match. The coach hopes that the difference in combat effectiveness between the two teams can be as small as possible to achieve the best training effect. Given the fighting power of 10 players, if you were a coach, how would you divide up the team to achieve the best training effect? Please output the minimum combat power difference under the unit plan.

Enter a description:

Combat power of 10 basketball players (integer, range [1,10000]), separated by spaces, such as: 10 9 8 7 6 5 4 3 2 1

There is no need to consider the scenario of abnormal input.

Output description:

The minimum combat power difference, such as: 1

Example 1

enter

10 9 8 7 6 5 4 3 2 1

output

1

illustrate

1 2 5 9 10 is divided into one team, 3 4 6 7 8 is divided into one team, the difference in combat effectiveness between the two teams is the smallest, and the output difference is 1. Remarks: The player team scheme is not unique, but the minimum combat power difference is fixed at 1.

This is a dynamic programming problem, which is difficult, and because it requires two groups to be divided into two groups, it is not easy to convert it into a typical knapsack problem.

Before knowing that this is a dynamic programming problem, I gave my own solution (at present, I think this solution should be wrong, but I haven't found a test case that can overthrow this solution, so I keep this solution for the time being).

The basic idea is:

1. First sort the players according to their combat effectiveness;

2. In order to ensure the balance of combat effectiveness, the strongest and weakest combat effectiveness can be divided into one group, so the first small group (the strongest and the weakest) is obtained. The sum of combat effectiveness in the period is SA, and they are divided into group A

3. In the remaining teams, find the combination with the closest combat power to SA, and divide it into group B. The sum of its combat power is SB, then find the largest and smallest combination, and then update SA (or SB, this needs to be in the middle Compare to see whether this combination is suitable for SA or SB), and then look for two combinations among the remaining combinations, so that the difference between SA and SB is the smallest until the last group;

4. The last group needs special treatment, because there may be only 2 players. At this time, it is necessary to allocate members reasonably according to the values ​​of SA and SB, and finally get the grouping result.

42.【Consecutive letter length】

Title description:

Given a string containing only uppercase letters, find the length of the kth longest substring among the substrings containing the same letter, and only take the longest substring with the same letter.
Enter a description:

The first line has a substring (1<length<=100) containing only uppercase letters.
The second line is the value of k
Output description:

Output the number of consecutive occurrences of the letter with the kth largest number of times.
example

enter:

AABAAA
2
output:

1
Description:

The same letter appears the most A 3 times in a row
The second most 2 times but A appears 3 times in a row
Input:

AAAAHHHBBCDHHHH
3
output:

2
instructions:

A and H are the most consecutive occurrences of the same letter,
H is the second most four times, 3 times
43. [Product of prime numbers]

**topic:

**RSA encryption algorithm is ubiquitous in the network security world. It takes advantage of the difficulty of factorization of extremely large integers. The larger the data, the higher the security factor. Given a 32-bit integer, please factorize it to find out is the product of two prime numbers.

44.【Judge whether a set of inequalities satisfy constraints and output the maximum difference】

Requirements: 1s 65535k

Given a set of inequalities, judge whether it is true and output the maximum difference of the inequalities (output the integer part of the floating point number)
Requirements:
1> The coefficient of the inequality is a double type, which is a two-dimensional array
2> The variable type of the inequality is an int type, which is a 3
> The target value of the inequality is a double type, which is a one-dimensional array
4> The constraint of the inequality is a string array, which can only be: ">",">=","=","<=","< "

Input description: a11, a12, a13, a14, a15; a21, a22, a23, a24, a25; a31, a32, a33, a34, a35; *1, *2, *3, *4, *5; b1, b2,b3,b4,b5;<=,<=,<=
Output description:
true or false, maximum difference

45.【The output string contains the minimum sum of all integers】

Title description:

The input string s output s contains the minimum sum of all integers
Explanation:

字符串s只包含az,AZ,+,-,
合法的整数包括正整数,一个或者多个0-9组成,如:0,2,3,002,102
负整数,负号开头,数字部分由一个或者多个0-9组成,如-2,-012,-23,-00023
输入描述:

包含数字的字符串
输出描述:

所有整数的最小和
示例

输入:

bb1234aa
输出:

10
输入:

bb12-34aa
输出:

-31
说明:

1+2-(34)=-31

46.【最大数】

给定一组非负整数,重新排列它们的顺序使之组成一个最大的整数。
示例 1:

输入: [10,2]
输出: 210
示例 2:

输入: [3,30,34,5,9]
输出: 9534330
说明: 输出结果可能非常大,所以你需要返回一个字符串而不是整数。

47.【找朋友】

在学校中,N个⼩朋友站成⼀队, 第i个⼩朋友的身⾼为height[i], 第i个⼩朋友可以看到的第⼀个⽐⾃⼰身⾼更⾼的⼩朋友j,那么j是i的好朋友(要求j > i)。
请重新⽣成⼀个列表,对应位置的输出是每个⼩朋友的好朋友位置,如果没有看到好朋友,请在该位置⽤0代替。
⼩朋友⼈数范围是 [0, 40000]。

输⼊描述:

第⼀⾏输⼊N,N表示有N个⼩朋友 第⼆⾏输⼊N个⼩朋友的身⾼height[i],都是整数

输出描述:

输出N个⼩朋友的好朋友的位置

示例1:
输入
2

100 95

输出

0 0

48.【字符统计及重排】

【字符统计及重排】给出⼀个仅包含字⺟的字符串,不包含空格,统计字符串中各个字⺟(区分⼤⼩写)出现的次数,并按照字⺟出现次数从⼤到⼩的顺序输出各个
字⺟及其出现次数。如果次数相同,按照⾃然顺序进⾏排序,且⼩写字⺟在⼤写字⺟之前。
输⼊描述:

输⼊⼀⾏,为⼀个仅包含字⺟的字符串。

输出描述:

按照字⺟出现次数从⼤到⼩的顺序输出各个字⺟和字⺟次数,⽤英⽂分号分隔,注意末尾的分号;字⺟和次数间⽤英⽂冒号分隔。

示例1:
输入

xyxyXX

输出

x:2;y:2;X:2

49.【乱序整数序列两数之和绝对值最小】

要求:1s 262144k
给定一个随机的整数数组(含正负整数),找出其中的两个数,其和的绝对值为最小值,并返回两个数,按从小到大返回以及绝对值。每种输入只会对应一个答案。但是,数组中同一个元素不能使用两遍

输入:通过空格分割的有序整数序列字符串,最多1000个,范围(-65535,65535)
输出:两数之和的绝对值最小值

eg:
输入: -1 -3 7 5 11 15
输出:-3 5 2

50.【德州扑克】

五张牌,每张牌由牌大小和花色组成,牌大小2~10、J、Q、K、A,牌花色为红桃、黑桃、梅花、方块四种花色之一。 判断牌型:

牌型1,同花顺:同一花色的顺子,如红桃2红桃3红桃4红桃5红桃6。

牌型2,四条:四张相同数字 + 单张,如红桃A黑桃A梅花A方块A + 黑桃K。

牌型3,葫芦:三张相同数字 + 一对,如红桃5黑桃5梅花5 + 方块9梅花9。

牌型4,同花:同一花色,如方块3方块7方块10方块J方块Q。

Card type 5, straight: a straight with different suits, such as hearts 2 spades 3 hearts 4 hearts 5 diamonds 6.

Card type 6, three of a kind: three of a kind + two singles.

Card type 7, other.

illustrate:

1) There will be no cards with exactly the same size and suit among the five cards.

2) The cards in the front are larger than the cards in the back, a straight flush is bigger than four of a kind, and so on.

Enter a description:

The input consists of 5 lines

Each line has a card size and suit, the card size is 2~10, J, Q, K, A, and the suits are represented by characters H, S, C, and D respectively for hearts, spades, clubs, and diamonds.

Output description:

Output the serial number of the card type. When 5 cards match multiple card types, take the largest card type serial number and output

Example 1

enter:

2 H

3 C

6 S

5 S

4 S

output:

5

51.【Reliable car】

Programmer Xiao Ming took a taxi to go to work. Out of professional sensitivity, he noticed that there was something wrong with the meter of this taxi, which was always too large.
The taxi driver explained that he didn't like the number 4, so he refitted the meter, and skipped any number where it encountered the number 4, and the rest of the functions were normal.
for example:

  1. 23再多一块钱就变为25;
    
  2. 39再多一块钱变为50;
    
  3. 399再多一块钱变为500;
    

Xiao Ming saw through the driver's trick, and was going to use his knowledge to defeat the driver's conspiracy.
Given the surface reading of the meter, return the actual cost.
Input Description:
Only one line, the number N, indicates the reading of the odometer. (1<=N<=888888888).
Output description:
A number representing the actual cost incurred. End with carriage return.
Example 1:
Input 5
Output 4
Explanation: 5 means the surface reading of the meter. 4 means that the actual cost is actually only 4 yuan.
Example 2:
Input 17
Output 15
Explanation: 17 means the surface reading of the meter. 15 means that the actual cost is only 15 yuan.
Example 3:
Input 100
and output 81
Explanation: 100 means the surface reading of the billing meter. 81 means that the actual cost is only 81 yuan.

52.【VLAN resource pool】

Title description:

***VLAN*** is a technology for logically dividing LAN devices. In order to identify different VLANs, the concept of VLAN ID (integer between 1-4094) is introduced.
Define a resource pool of VLAN IDs (hereinafter referred to as the VLAN resource pool). Continuous VLANs in the resource pool are represented by start VLAN-end VLAN, and discontinuous ones are represented by a single integer. All VLANs are connected with English commas. Now
there is a VLAN resource pool. The business needs to apply for a VLAN from the resource pool. You need to output the resource pool after removing the applied VLAN from the VLAN resource pool.
Enter a description:

The first line is the VLAN resource pool in string format, and the second line is the VLAN to be applied for by the business. The value range of VLAN is an integer between [1,4094].
Output description:

从输入VLAN资源池中移除申请的VLAN后字符串格式的VLAN资源池,输出要求满足题目描述中的格式,并且按照VLAN从小到大升序输出。
如果申请的VLAN不在原VLAN资源池内,输出原VLAN资源池升序排序后的字符串即可。
备注:

输入VLAN资源池中VLAN的数量取值范围为[2-4094]间的整数,资源池中VLAN不重复且合法([1,4094]之间的整数),输入是乱序的。

示例

输入:

1-5
2
输出:

1,3-5
说明:

原VLAN资源池中有VLAN 1、2、3、4、5,从资源池中移除2后,剩下VLAN 1、3、4、5,按照题目描述格式并升序后的结果为1,3-5。
输入:

20-21,15,18,30,5-10
15
输出:

5-10,18,20-21,30
说明:

原VLAN资源池中有VLAN 5、6、7、8、9、10、15、18、20、21、30,从资源池中移除15后,资源池中剩下的VLAN为 5、6、7、8、9、10、18、20、21、30,按照题目描述格式并升序后的结果为5-10,18,20-21,30。
输入:

5,1-3
10
输出:

1-3,5
说明:

原VLAN资源池中有VLAN 1、2、3,5,申请的VLAN 10不在原资源池中,将原资源池按照题目描述格式并按升序排序后输出的结果为1-3,5。

53.【任务最优调度】

【任务最优调度】给定一个正整数组表示待系统执行的任务列表,数组的每一个元素代表一个任务,元素的值表示该任务的类型。请计算执行完所有任务所需的最短时间。
任务执行规则如下:
1、任务可以按任意顺序执行,且每个任务执行耗时间均为1个时间单位。
2、两个同类型的任务之间必须有长度为N个单位的冷却时间,比如N为2时,在时间K执行了类型3的任务,那么K+1和K+2两个时间不能执行类型3任务。
3、系统在任何一个单位时间内都可以执行一个任务,或者等待状态。说明:数组最大长度为1000,速度最大值1000。
输入描述:
第一行记录一个用半角逗号分隔的数组,数组长度不超过1000,数组元素的值不超过1000第二行记录任务冷却时间,N为正整数,N<=100。
输出描述:
输出为执行完所有任务所需的最短时间。
示例:
输入
2,2,2,3
2
输出
7

54.【找终点】

 55.【拼接URL】

题目描述:

给定一个url前缀和url后缀,通过,分割 需要将其连接为一个完整的url
如果前缀结尾和后缀开头都没有/,需要自动补上/连接符
如果前缀结尾和后缀开头都为/,需要自动去重
约束:不用考虑前后缀URL不合法情况
输入描述:

url前缀(一个长度小于100的字符串) url后缀(一个长度小于100的字符串)
输出描述:

拼接后的url
示例

输入:

/acm,/bb
output:

/acm/bb
input:

/abc/,/bcd
output:

/abc/bcd
input:

/acd,bef
output:

/acd/bef
input:

,
output:

/

56.【Matrix maximum value】

Title description:
Given an N*N two-dimensional matrix containing only 0 and 1, please calculate the maximum value of the two-dimensional matrix. The calculation rules are as follows:

The elements of each row form a binary number in subscript order (the larger the subscript, the lower the order), and the value of the binary number is the value of the row. The sum of the row values ​​of a matrix is ​​the value of the matrix.
Allows changing the position of individual elements within a row by moving each row's elements cyclically left or right in its entirety. For example:
[1,0,1,1,1] moves 2 bits to the right as a whole to become [1,1,1,0,1], the binary number is 11101, and the value is 29.
[1,0,1,1,1] moves 2 bits to the left as a whole to become [1,1,1,1,0], the binary number is 11110, and the value is 30.
Input description:
The first line of input is a positive integer, recording the size of N, 0 < N <= 20.
The input lines 2 to N+1 are two-dimensional matrix information, and the elements in the line are separated by half-width commas.
Output description:
The maximum value of the matrix.

Example 1:

Enter
5
1,0,0,0,1
0,0,0,1,1
0,1,0,1,0
1,0,0,1,1
1,0,1,0,1
1
2
3
4
5
6
Output
122
1
Explanation:
The first line is shifted 1 bit to the right as a whole, and the maximum value [1,1,0,0,0] of this line is obtained, which is 11000 in binary and 24 in decimal.
The second line moves 2 bits to the right as a whole to obtain the maximum value [1,1,0,0,0] in this line, which is 11000 in binary and 24 in decimal.
The third line moves 1 bit to the left as a whole to get the maximum value [1,0,1,0,0] in this line, which is 10100 in binary and 20 in decimal.
The fourth line moves 2 bits to the right as a whole to obtain the maximum value [1,1,1,0,0] in this line, which is 11100 in binary and 28 in decimal.
The fifth line moves 1 bit to the right as a whole to get the maximum value [1,1,0,1,0] in this line, which is 11010 in binary and 26 in decimal.
The sum is 24+24+20+28+26=122.

57.【Minimum transmission delay】

Problem Description:

There is an M*N node matrix, each node can forward data packets in 8 directions (up, down, left, right and four slash directions), each node will consume a fixed delay when forwarding, two consecutive phases Simultaneous delay can reduce a delay value (that is, when there are K nodes with the same delay forwarding continuously, it can reduce K-1 delay value), find the upper left corner (0, 0) and start forwarding data packets to the lower right corner (M -1, N- 1) and forward the shortest delay.

输入:
第一行两个数字,M、N,接下来有M行,每行有N个数据,表述M* N的矩阵。
输出:
最短时延值。

示例1:
3 3
0 2 2
1 2 1
2 2 1
输出:3
示例2:
3 3
2 2 2
2 2 2
2 2 2
输出:4(2 + 2 + 2 -(3-1))

58.【高效的任务规划】

Title description:
You have n machines numbered 1~n, each of which needs to complete a job, and the machines can complete a job independently after configuration. Suppose you need to spend B minutes to set up the i-th machine, then start running, and complete the task after J minutes. Now, you need to choose the order in which to arrange the tasks so that all the tasks are completed in the shortest time. Note that two machines cannot be configured at the same time, but the configured machines can perform their respective jobs at the same time.
Input description:
The first line of input represents a total of M groups of task data (1 < M <= 10).
The first line of each set of data is an integer specifying the number N of machines (0 < N <= 1000). The next N lines each contain two integers, the first representing B (0 <= B <= 10000) and the second representing J (0 <= J <= 10000).
Each set of data is entered consecutively without being separated by blank lines. Each set of tasks is timed individually.
Output description:
For each group of tasks, output the shortest completion time, and the results of each group occupy a single row. For example, two sets of tasks should have two lines of output.
Example 1:
Input
1
1
2 2
Output
4

59.【Maximum number of components】

【Description】

Given a set of non-negative integers, rearrange them to form the largest integer.

【Example】

Input: [10,2]
Output: 210
Input: [3,30,34,5,9]
Output: 9534330

60.【Area of ​​intersection of rectangles】 

【矩形相交的面积】在坐标系中,给定3个矩形,求相交区域的面积。
输入描述:
3行输入分别为3个矩形的位置,分别代表“左上角x坐标”,“左上角y坐标”,“矩形宽”,“矩形高” -1000<=x,y<1000
输出描述:
输出3个矩形相交的面积,不相交的输出0

示例:
输入
1 6 4 4
3 5 3 4
0 3 7 3
输出
2

61.【实现一个简易内存池】 

题目描述
请实现一个简易内存池,根据请求命令完成内存分配和释放。
内存池支持两种操作命令,REQUEST和RELEASE,其格式为:
REQUEST=请求的内存大小 表示请求分配指定大小内存,如果分配成功,返回分配到的内存首地址;如果内存不足,或指定的大小为0,则输出error。
RELEASE=释放的内存首地址 表示释放掉之前分配的内存,释放成功无需输出,如果释放不存在的首地址则输出error。
注意:
1.内存池总大小为100字节。
2.内存池地址分配必须是连续内存,并优先从低地址分配。
3.内存释放后可被再次分配,已释放的内存在空闲时不能被二次释放。
4.不会释放已申请的内存块的中间地址。
5.释放操作只是针对首地址所对应的单个内存块进行操作,不会影响其它内存块。
解答要求
时间限制: 1000ms, 内存限制: 256MB
首行为整数 N , 表示操作命令的个数,取值范围:0 < N <= 100。
接下来的N行, 每行将给出一个操作命令,操作命令和参数之间用 “=”分割。

Input output
Example 1:
2
REQUEST=10
REQUEST=20 Output
example 1:
0
10
1.
2.
3. 4.
5.
6.
7. Example 2: 5 REQUEST=10 REQUEST=20 RELEASE=0 REQUEST= 20 REQUEST=10 output sample 2: 0 10 30 0 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. Prompt description: the first command, application address 0~9 10 bytes of memory, return the first address 0, the second instruction, apply for 20 bytes of memory at addresses 10~29, return the first address 10, and the third instruction, release the memory application with the first address 0, 0~9 address memory Released, becomes idle, released successfully, no output required





























第四条指令,申请20字节内存,09地址内存连续空间不足20字节,往后查找到3049地址,返回首地址30
第五条指令,申请10字节,0~9地址内存空间足够,返回首地址0

62.【工厂流水线调度】

题目描述:

一个工厂有m条流水线,来并行完成n个独立的作业,该工厂设置了一个调度系统,在安排作业时,总是优先执行处理时间最短的作业。
现给定流水线个数m,需要完成的作业数n, 每个作业的处理时间分别为t1,t2…tn。请你编程计算处理完所有作业的耗时为多少?
当n>m时,首先处理时间短的m个作业进入流水线,其他的等待,当某个作业完成时,依次从剩余作业中取处理时间最短的进入处理。
输入描述:

第一行为2个整数(采用空格分隔),分别表示流水线个数m和作业数n
第二行输入n个整数(采用空格分隔),表示每个作业的处理时长t1,t2…tn。
0< m,n<100
0<t1,t2…tn<100
注:保证输入都是合法的。
输出描述:

输出处理完所有作业的总时长
示例

输入:

3 5
8 4 3 2 10
输出:

13
说明:

先安排时间为2、3、4的3个作业。
第一条流水线先完成作业,然后调度剩余时间最短的作业8。
第二条流水线完成作业,然后调度剩余时间最短的作业10。
总工耗时就是第二条流水线完成作业的时间13(3+10)。

63.【快递运输】

【题目描述】

A truck delivering couriers, the couriers delivered are all placed in cuboid courier boxes of different sizes. In order to be able to load more couriers without overloading the truck, it is necessary to calculate how many couriers can be loaded at most.
The size of the courier is not limited, the number of couriers is up to 1,000, and the maximum load of the truck is 50,000.
Input description
The first line enters the weight of each courier, separated by English commas, such as: 5,10,2,11 The
second line enters the load capacity of the truck, such as: 20
No need to consider abnormal input
Output description
Output the maximum amount that can be loaded Express delivery, such as: 3
【Example】

Input:
5, 10, 2,
11 20
Output:
3
Explanation:
The load capacity of the truck is 20, and there can only be three couriers 5, 10, 2 at most, so the output is 3

64.【Delete directory】

Requirements: 1s 262144k

There are N directories in a file system, and each directory has a unique ID. Each directory has only one parent directory, but each parent directory can have zero or more subdirectories, and the directory structure is a tree structure.
Assume that the ID of the root directory is 0, and the root directory has no parent directory, and the IDs of all other directories are represented by unique positive integers and numbered uniformly.
Given a directory ID and its parent directory ID corresponding parent-child relationship table [subdirectory ID, parent directory ID], and a directory ID to be deleted, please calculate and return an ID sequence, indicating that the remaining For all directories, the returned ID sequence is output in ascending order.
Note:
1. The directory or file number to be deleted must be in the input ID sequence;
2. When a directory is deleted, all its subdirectories will be deleted.

Input description: The first input line is the length m of the parent-child relationship table; the next m lines are m parent-child relationship pairs; the last line is the ID to be deleted. The elements in the sequence are separated by spaces, see example.

Output description: Output a sequence indicating the remaining directory ID after deleting the specified directory.

Example 1
Input
5
8 6
10 8
6 0
20 8
2 6
8

output
2 6
1
2
3
4
5
6
7
8
9
10
11
12

 65.【Task scheduling problem】

Operating system task scheduling problem. Operating system tasks are divided into two types: system tasks and user tasks. Among them, the priority of the system task is < 50, and the priority of the user task is >= 50 and <= 255. Tasks with a priority greater than 255 are illegal tasks and should be eliminated. There is a task queue task[] with a length of n, and the element value in the task indicates the priority of the task. The smaller the value, the higher the priority. The function scheduler realizes the following functions, and stores the tasks in task[] into the system_task[] array and user_task[] array in sequence according to the system tasks and user tasks (the value of the element in the array is the subscript of the task in the task[] array) , and the tasks with higher priority are in front, and the array element is -1 to indicate the end.

例如:task[] = {0, 30, 155, 1, 80, 300, 170, 40, 99} system_task[] = {0, 3, 1, 7, -1} user_task[] = {4, 8, 2, 6, -1}

函数接口 void scheduler(int task[], int n, int system_task[], int user_task[])

66.【English input method word association】

Title description:

The supervisor expects you to realize the word association function of the English input method.
The requirements are as follows: According to the prefix of the word input by the user, associate the word that the user wants to input from the input English sentence, and output the associated word sequence in lexicographical order. If it cannot be associated, please output the prefix of the word entered by the user.
Notice:

English word association is case-sensitive and abbreviated forms such as "don't" are judged as two words "don" and "t". The output word sequence cannot have repeated words and can only be English words without punctuation marks.
Enter a description:

Enter two lines

In the first line, enter a statement str consisting of English words word and punctuation

The next line is an English word prefix pre

0 < word.length() <= 20

0 < str.length <= 10000

0 < pre <=20

Output description:

Output the word sequence or word prefix that meets the requirements. When there are more than one, the words are separated by a single space.
Example

enter:

I love you
He
输出:

He
explains:

The user has entered the word sentence "I love you", and extracted the three words "I", "love" and "you". Then the user enters "He", and the word that meets the requirements cannot be associated from the input information, so Outputs word prefixes entered by the user.
enter:

The furthest distance in the world,Is not between life and death,But when I stand in front or you,Yet you don’t know that I love you.
f
输出:

front furthest
 

67.【Solving continuous series】

[Solving continuous series] It is known that the sum of each number of continuous positive integer series {K}=K1, K2, K3...Ki is S, i=N (0<S<100000, 0<N<100000), find This number sequence K.
Enter a description:

The input contains two parameters, 1) the sequence of continuous positive integers and S, 2) the number N of numbers in the sequence.

Output description:

If there is a solution, output the sequence K, if there is no solution, output -1

Example 1:
Input

525 6

output:

85 86 87 88 89 90
 

68.【Interval Intersection】

[Interval Intersection] Given a set of closed intervals, some intervals have intersections. The intersection of any two given intervals is called a public interval (for example: the public interval of [1,2], [2,3] is the public interval of [2,2], [3,5], [3,6] The interval is
[3,5]). If there is an intersection between the public intervals, they need to be merged (eg: [1,3], [3,5] intervals have an intersection [3,3], which needs to be merged into [1,5]). Output the merged list of intervals in ascending order.
Input description: A list of intervals, the number of intervals is N: 0<=N<=1000; the interval elements are X: -10000<=X<=10000.
Output description: A list of merged intervals arranged in ascending order
Remarks:
1. The interval elements are all numbers, and abnormal inputs such as letters and symbols are not considered.
2. A single interval is identified as no public interval.
Example:
input
[[0, 3], [1, 3], [3, 5], [3, 6]]
output
[[1, 5]]

69.【A Master of Cards】

Title: Card Player | Time Limit: 1 second | Memory Limit: 32768K | Language Limit: Unlimited

给定一个长度为n的整型数组,表示一个选手在n轮内可选择的牌面分数。选手基于规则选牌,请计算所有轮结束后其可以获得的最高总分数。选择规则如下:

1、在每轮里选手可以选择获取该轮牌面,则其总分数加上该轮牌面分数,为其新的总分数。

2、选手也可不选择本轮牌面直接跳到下一轮,此时将当前总分数还原为3轮前的总分数,若当前轮次小于等于3(即在第1、2、3轮选择跳过轮次),则总分数置为0。

3、选手的初始总分数为0,且必须依次参加每一轮。

输入描述:

第一行为一个小写逗号分割的字符串,表示n轮的牌面分数,1<= n <=20。

分数值为整数,-100 <= 分数值 <= 100。

不考虑格式问题。

输出描述:

所有轮结束后选手获得的最高总分数。

示例1

输入

1,-5,-6,4,3,6,-2

输出

11

说明

总共有7轮牌面。

第一轮选择该轮牌面,总分数为1。

第二轮不选择该轮牌面,总分数还原为0。

第三轮不选择该轮牌面,总分数还原为0。

第四轮选择该轮牌面,总分数为4。

第五轮选择该轮牌面,总分数为7。

第六轮选择该轮牌面,总分数为13。

第七轮如果不选择该轮牌面,则总分数还原到3轮1前分数,即第四轮的总分数4,如果选择该轮牌面,总分数为11,所以选择该轮牌面。

因此,最终的最高总分为11。
 

70.【根据日志时间先后顺序对日志进行排序】

运维工程师采集到某产品线网运行一天产生的日志n条
现需根据日志时间先后顺序对日志进行排序
日志时间格式为H:M:S.N
H表示小时(0~23)
M表示分钟(0~59)
S表示秒(0~59)
N表示毫秒(0~999)
时间可能并没有补全
也就是说
01:01:01.001也可能表示为1:1:1.1

Input description
   Enter an integer n in the first line to indicate the number of logs
   1<=n<=100000
   Enter n time in the next n lines

 The output describes
   the time after sorting in ascending order of time.
   If there are two times that represent the same time,
   keep the input order

 Example:
   Input:
    2
    01:41:8.9
    1:1:09.211
   Output
     1:1:09.211
     01:41:8.9
 Example
    Input
     3
     23:41:08.023
     1:1:09.211
     08:01:22.0
    Output
      1:1:09.211
      08:01:22.0
      23:41:08.023

  Example
    input
      2
      22:41:08.023
      22:41:08.23
    output
      22:41:08.023
      22:41:08.23
    time same keep input order

71.【Moon cakes】

Title description
  Mid-Autumn Festival, the company distributes moon cakes, m employees buy n moon cakes, m<=n, each employee gets at least 1 moon cake, but can divide more than one, the maximum number of moon cakes for a single person is Max1 , the number of mooncakes assigned to a single person is Max2, Max1-Max2<=3,. Similarly, Max(n-1) is the number of n-1 moon cakes for a single person, Max(n) is the number of n-th moon cakes for a single person, Max(n-1)-Max( n)<=3. How many ways are there to divide mooncakes?

Enter a description:

Input mn in the first line, which means m employees, n moon cakes, m<=n
1
output description:

Output how many kinds of moon cakes there are
1
problem-solving idea:
  treat n moon cakes as a line segment and divide them m times.

Assume, start dividing once and divide a mooncake, then at this time m=m-1, n=na; when
dividing again, divide b mooncake, then at this time m=m-1, n=nb;
...
Finally When dividing for the nth time, divide c mooncakes, m=m-1=0, n=nc=0;

71.【Sliding window maximum value】

[Programming Questions | 100 points] Maximum Sliding Window [ 2022 Q1 Exam Questions ]

This question can be coded using a local IDE, and existing local code cannot be used. No jumping restrictions, please click the "Save and Submit" button to submit the code after coding.

Title description:
There is an array of N integers and a window of length M. The window slides from the first number in the array until the window cannot slide. Each time the window slides, a window sum (all numbers in the window) is generated. and), find the maximum value of all window sums generated by window sliding.

Input description:
Input a positive integer N in the first line, indicating the number of integers. (0<N<100000)
Enter N integers in the second line, and the range of integers is [-100,100].
The third line enters a positive integer M, M represents the size of the window, M<=100000, and M<=N.
Output description:
Window sliding yields the maximum of all window sums.
Example 1 The input and output examples are only for debugging, and the background judgment data generally does not include examples

Input
6
12 10 20 30 15 23
3
1
2
3
Output
68
1
Idea analysis:
This is different from the maximum value of the sliding window of leetcode, which needs to be implemented with a monotonic stack. Compute the maximum value for each window.

For this question, you can refer to the monotone stack implementation method, which is used to count the maximum value of the sliding window. It can also be implemented using double pointers.

72.【Wave Array Finding Alphabet Game】

Title description:

Word Maze is a small online game where you need to find the foods marked with letters, but ask to eat them in the order of the letters of the given word. As shown in the figure above, assuming that given the word if, you must eat i before you can eat f.

但现在你的任务可没有这么简单,你现在处于一个迷宫Maze(n×m的矩阵)当中,里面到处都是以字母标注的食物,但你只能吃掉能连成给定单词W的食物。
  • 1
  • 2

, specifying W as "SOLO", the word "SOLO" is marked in red on the map.

Pay attention to the distinction between upper and lower case of English letters, you can only walk up, down, left, and right.

Runtime Limit: Unlimited
Memory Limit: Unlimited

enter:

The first line of input contains two integers n, m (0

output:

If the given word can be connected in the map, output "YES", otherwise output "NO". Note: Each letter can only be used once.

Sample input:

5 5
SOLO
CPUCY
EKLQH
CRSOL
EKLQO
PGRBC

样例输出:

YES

思路分析:

  • 这道题同样对时间和空间没有要求,所以采用暴力破解
  • 遍历二位数组,寻找对应的单词的字母,找到了要set=‘’,然后conninue

73.【最小数字】

编程题目 | 100分】最小数字 [ 100 / 中等 ]

最小数字
题目描述:
给定一个整型数组,请从该数组中选择3个元素组成最小数字并输出(如果数组长度小于3,则选择数组中所有元素来组成最小数字)。

输入描述:
一行用半角逗号分割的字符串记录的整型数组,0 < 数组长度 <= 100,0 < 整数的取值范围 <= 10000。

输出描述:
由3个元素组成的最小数字,如果数组长度小于3,则选择数组中所有元素来组成最小数字。

示例 1:
输入
21,30,62,5,31
1
输出
21305
1
说明
数组长度超过3,需要选3个元素组成最小数字,21305由21,30,5三个元素组成的数字,为所有组合中最小的数字

示例 2:
输入
5,21
1
输出
215
1
说明
数组长度小于3,选择所有元素组成最小值,215为最小值
 

74.【解密犯罪时间】

解密犯罪时间 | 时间限制:1秒 | 内存限制:262144K | 语言限制:不限
警察在侦破一个案件时,得到了线人给出的可能犯罪时间,形如 “HH:MM” 表示的时刻。
根据警察和线人的约定,为了隐蔽,该时间是修改过的,解密规则为:利用当前出现过的数字,构造下一个距离当前时间最近的时刻,则该时间为可能的犯罪时间。每个出现数字都可以被无限次使用。"
"输入描述:
形如HH:SS的字符串,表示原始输入
输出描述:
形如HH:SS的字符串,表示推理出来的犯罪时间
示例1
输入
18:52
输出
18:55
说明
利用数字1, 8, 5, 2构造出来的最近时刻是18:55,是3分钟之后。结果不是18:51因为这个时刻是18小时52分钟之后。
示例2
输入
23:59
输出
22:22
说明
利用数字2, 3, 5, 9构造出来的最近时刻是22:22。 答案一定是第二天的某一时刻,所以选择可构造的最小时刻为犯罪时间。
备注:

可以保证线人给定的字符串一定是合法的。例如,“01:35” 和 “11:08” 是合法的,“1:35” 和 “11:8” 是不合法的。
最近的时刻有可能在第二天

75.【任务最优调度】

[Task Optimal Scheduling] A positive integer group is given to represent the list of tasks to be executed by the system. Each element of the array represents a task, and the value of the element represents the type of the task. Calculate the minimum time required to complete all tasks.
The task execution rules are as follows:
1. Tasks can be executed in any order, and the execution time of each task is 1 time unit.
2. There must be a cooling time of N units between two tasks of the same type. For example, when N is 2, and a type 3 task is executed at time K, then K+1 and K+2 cannot be executed Type 3 tasks.
3. The system can execute a task or wait in any unit time. Note: The maximum length of the array is 1000, and the maximum speed is 1000.
Input description:
The first line records an array separated by half-width commas. The length of the array does not exceed 1000, and the value of the array elements does not exceed 1000. The second line records the task cooling time. N is a positive integer, and N<=100.
Output description:
The output is the minimum time required to execute all tasks.
Example:
input
2,2,2,3
2
output
7

76.【Maximum value】

Given a set of non-negative integers, rearrange them to form the largest integer. (LeetCode-JAVA)
Example 1:

Input: [10,2]
Output: 210
Example 2:

Input: [3,30,34,5,9]
Output: 9534330
Explanation: The output may be very large, so you need to return a string instead of an integer.

77.【Arranging by height and weight】

Title description:

A school held a sports meeting, and the students were identified by numbers (1, 2, 3...n). Now it is necessary to arrange them according to their height from low to high. For people with the same height, they should be arranged according to their weight from light to heavy. For those with the same height and weight Person, maintain the original numbering sequence relationship.
Please output the sorted student number
Enter description:

Two sequences, each sequence consists of N positive integers, (0<n<=100).
The values ​​in the first sequence represent height and
the values ​​in the second sequence represent weight
Output description:

Arrange the results, each value is the student number in the original sequence, the number starts from 1, the height is from low to high, the height is the same and the weight is from light to heavy, and the weight is the same to maintain the original order.
Example:

enter:

4
100 100 120 130
40 30 60 50
output:

2134
input:

3
90 110 90
45 60 45
output:

132
 

78.【Looking for children with similar height】

Xiaoming entered the first
grade of primary school this year. After coming to the new class, he found that the heights of other children were uneven.
Then he wanted to sort them based on the height difference between the children and himself.
Please help him realize the sorting .
Enter the first row of the description to be
a positive integer h and n
0<h<200 is Xiao Ming’s height
0<n<50 is the number of other children in the new class
The second row is n positive integers
h1 ~ hn are the heights of other children respectively The
value range is 0<hi<200
and n positive integers Integers vary

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

输出描述

 输出排序结果,各正整数以空格分割

 和小明身高差绝对值最小的小朋友排在前面

 和小明身高差绝对值最大的小朋友排在后面

 如果两个小朋友和小明身高差一样

 则个子较小的小朋友排在前面

 示例一

 输入

 100 10

 95 96 97 98 99 101 102 103 104 105

 输出

  99 101 98 102 97 103 96 104 95 105

 说明  小明身高100

 班级学生10个  身高分别为95 96 97 98 99 101 102 103 104 105,按身高差排序后结果为:99 101 98 102 97 103 96 104 95 105

79.【Binary tree inorder traversal output】 

Title Description
According to the given binary tree structure description string, output the binary tree according to the inorder traversal result string. The order of inorder traversal is: left subtree, root node, right subtree.

Input description
A string consisting of uppercase and lowercase letters, left and right curly brackets, and commas:
1. The letter represents a node value, and the left and right brackets contain the child nodes of the node.
2. The left and right sub-nodes are separated by commas. If the comma is empty, the left sub-node is empty, and if there is no comma, the right sub-node
is empty.
3. The maximum number of binary tree nodes does not exceed 100.
Note: The format of the input string is correct, and there is no need to consider the case of format errors.

Output description
Output a character string, which is the concatenation result of each node value in the binary tree inorder traversal.

Example:
Input: a{b{d, e{g,h{,I}}}, c{f}}
Output: dbgehiafc

80.【kth permutation】

Topic
[kth arrangement] Given a parameter n, there will be n integers from 1 to n: 1, 2, 3, ..., n, and these n numbers have a total of n! kind of permutation.
List all permutations in ascending order of size and mark them one by one. When n=3, all permutations are as follows:
"123"
"132"
"213"
"231"
"312"
"321"
Given n and k, return The kth permutation.
Input description:
Input two lines, the first line is n, the second line is k, the range of given n is [1, 9], and the range of given k is [1, n!].

输出描述:
输出排在第k位置的数字。

示例1:
输入:
3
3

输出:
213
 

81.【求数组中最大n个数和最小n个数的和】

题目描述
输入一个数 M ,表示数组中有 M 个数
输入 M 个数。
输入 n
求数组 M 中,去除重复值后,最大 n 个数和最小 n 个数的和
注意:最大和最小的数中不能有重复值,否则输出 -1

样例输入
5
3 3 2 4 2
2
样例输出
-1
说明
去除重复后最大的2个数为[4,3],最小的2个数为[2,3];有相同值,所以返回-1

样例输入
5
3 3 2 4 2
1
样例输出
6
说明
去除重复后最大的1个数为[4],最小的1个数为[2];没有相同值,返回6
 

82.【喊7的次数重排】

题目描述
喊7是一个传统的聚会游戏,N个人围成一圈,按顺时针从1到N编号。编号为1的人从1开始喊数,下一个人喊的数字为上一个人的数字加1,但是当数字是7的倍数或者数字本身含有7的话,要喊"过"。现给定一个长度为N的数组,存储了打乱顺序的每个人喊"过"的次数,请把它还原成正确的顺序,即数组的第i个元素存储编号i的人喊"过"的次数。

Input
The input is a line, the number of times to shout "pass" separated by spaces

Sample input
0 1 0

Sample output
1 0 0

Explanation
There is only one time to shout "Pass", and that will only happen when you need to shout 7. According to the sequence, the person numbered 1 will encounter 7, so output 1 0 0 . Note that the K at the end is not necessarily 7, it can also be 8, 9, etc., and the number of shouts is 1 0 0 .
 

83.【Arrays are used to store binary trees】

Binary trees can also be stored in arrays. Given an array, the value of the root node of the tree is stored at subscript 1. For
a node stored at subscript n, its left and right child nodes are stored at subscripts 2*n and 2*n+ respectively. 1 and we use -1 to represent that a node is empty. Given a binary tree stored in an array , try to find the path from the root node to the smallest leaf node. The path consists of the value of the node






Input description
Enter the content of an array.
Each element of the array is a positive integer, and the elements are separated by spaces.
Note that the first element is the value of the root node,
that is, the nth element of the array corresponds to the subscript n
subscript 0 in the tree representation is not used in
, so we omit
the input tree with a maximum of 7 layers

Output Description
 Output the value of each node on the path from the root node to the smallest leaf node,
 separated by spaces
 Use cases to ensure that there is only one smallest leaf node

 例子
  输入
  3 5 7 -1 -1 2 4
  输出
   3 7 2

  例子
   输入
  5 9 8 -1 -1 7 -1 -1 -1 -1 -1 6
   输出
  5 8 7 6
 

84.【最大子矩阵和】

求一个M*N的矩阵的最大子矩阵和。
比如在如下这个矩阵中:
 0 -2 -7  0
 9  2 -6  2
-4  1 -4  1
-1  8  0 -2 
拥有最大和的子矩阵为:
 9 2
-4 1
-1 8
其和为15。

85.【磁盘容量排序】

磁盘的容量单位常用的有M,G,T这三个等级,关系为 1T = 1024G、1G = 1024M,如样例所示先输入磁盘的个数,再依次输入磁盘的容量大小,然后按照从小到大的顺序对磁盘容量进行排序并输出。

样例:
输入:
3
1G
2G
1024
输出:(容量相等,保留原来的相对位置)
1G
1024
2G

86.【一种字符串压缩表示的解压】

有一种简易压缩算法:针对全部由小写英文字母组成的字符串,将其中连续超过两个相同字母的部分压缩为连续个数加该字母,其他部分保持原样不变。
例如:字符串“aaabbccccd”经过压缩成为字符串“3abb4cd”。请您编写解压函数,根据输入的字符串,判断其是否为合法压缩过的字符串,若输入合法则输出解压缩后的字符串,否则输出字符串“!error”来报告错误。
输入描述:

若判断输入为合法的经过经过压缩后的字符串,则输出压缩前的字符串;若输入不合法,则输出字符串“!error”。

示例1:

输入

4dff

输出

ddddff

87.【最大花费金额】

双十一众多商品进行打折销售,小明想购买自己心仪的一些物品,但由于受购买资金限制,所以他决定从众多心仪商品中购买三件,而且想尽可能的花完资金,现在请你设计一个程序帮助小明计算尽可能花费的最大资金数额。

输入描述:

  • 输入第一行为一维整型数组M,数组长度小于100,数组元素记录单个商品的价格,单个商品价格小于1000。
  • 输入第二行为购买资金的额度R,R小于100000。

输出描述:

  • 输出为满足上述条件的最大花费额度。

注意:

  • 如果不存在满足上述条件的商品,请返回-1。

示例1

输入

23,26,36,27

78

输出

76

说明

金额23、26和27相加得到76,而且最接近且小于输入金额78

示例2

输入

23,30,40

26

输出

-1

说明

  • 因为输入的商品,无法组合出来满足三件之和小于26.故返回-1

备注:

  • 输入格式是正确的,无需考虑格式错误的情况。

88.【最远足迹】

题目描述:
某探险队负责对地下洞穴进行探险。 探险队成员在进行探险任务时,随身携带的记录器会不定期地记录自身的坐标,但在记录的间隙中也会记录其他数据。 探索工作结束后,探险队需要获取到某成员在探险过程中相对于探险队总部的最远的足迹位置。

When the instrument records the coordinates, the data format of the coordinates is (x,y), such as (1,2), (100,200), where 0<x<1000, 0<y<1000. At the same time, there are illegal coordinates, such as (01,1), (1,01), and (0,100) are illegal coordinates.
Set the coordinates of the expedition headquarters to (0,0), and the distance from a certain location to the headquarters is: x * x + y * y.
If the two coordinates have the same distance from the headquarters, the first arrived coordinate is the farthest footprint.
If the coordinates in the recorder are not valid, output the headquarters coordinates (0,0). Remarks: There is no need to consider the nesting of double-layer brackets, such as sfsdfsd((1,2)).
Input description:
A string representing the data in the logger.

Such as: ferga13fdsf3(100,200)f2r3rfasf(300,400)

Output description:
A string representing the coordinates of the furthest trail.

Such as: (300,400)

Example 1:

Input
ferg(3,10)a13fdsf3(3,4)f2r3rfasf(5,10)
1
output
(5,10)
1
indicates that
there are 3 legal coordinates in the recorder: (3,10), (3,4), (5,10), where (5,10) is the farthest coordinate from the headquarters, outputs (5,10).

Example 2:

Input
asfefaweawfaw(0,1)fe
1
and output
(0,0)
1
, indicating that
the coordinates in the recorder are not legal, output the headquarters coordinates (0,0)

89.【Calculation area】

[calculated area]

The initial position i of the drawing pen of the drawing machine is at the origin (0.0). After the machine is started, its drawing pen draws a straight line according to the following rules:

1) Try to draw a straight line along the horizontal coordinate axis until the given end point value E,

2) During the period, it can be shifted in the direction of the ordinate axis by command. At the same time, the straight line is precisely drawn, and the straight line is drawn according to rule 1 after the offset; the format of the command is X oseYr. Indicates that the abscissa X is offset along the ordinate direction, a positive number of offset indicates a positive offset, and a negative number indicates a negative offset.

The abscissa grid point value E. and several inspection instructions are given. Please calculate the given straight line and abscissa axis. And the area of ​​the graph formed by the straight lines of XE.

Input mode:

The first row contains two integers NE. Indicates that there are N instructions. The end point value of the abscissa of the machine running E.

Next N lines. Two integers per line represent - bar instruction x osorr. The use case guarantees that the abscissa X appears in ascending order. And the same abscissa meaning will not appear. Value range: 0<Nc= 1000.00 X<= E <20000.10000 < oter such as 1000.

Output description:

An integer representing the calculated area. Guaranteed by use case. The result is in the range 0-4294967295

Example 1:

enter

4 10

11

21

31

4-2

output

12
 

 90.【Maximum Matrix Sum】

topic description

Given a two-dimensional integer matrix, it is necessary to select a sub-matrix in this matrix so that the sum of all the numbers in this sub-matrix is ​​as large as possible. We call this sub-matrix the sum-maximum sub-matrix. The principle of sub-matrix selection is the original A mutually contiguous rectangular area in the matrix.

Enter a description:

  • The first line of input contains 2 integers n, m (1 <= n, m <= 10), representing a matrix of n rows and m columns, and there are n rows below, and each row has m integers. In the same row, each There is 1 space between 2 numbers, there is no space after the last number, and all numbers are between [-1000, 1000].

Output description:

  • Output a line with a number representing the sum of all numbers in the selected sum-maximum sub-matrix.

Example 1

enter

3 4

-3 5 -1 5

2 4 -2 4

-1 3 -1 3

output

20

illustrate

In a 3*4 matrix, the sum of the sub-matrices in the last 3 columns adds up to 20, and the maximum.

91.【The longest broadcast response】

 Enter a description:

The first input line is two positive integers, respectively representing the number N of network nodes and the length I of the delay list;

The next line I is input, which represents a list of connection relationships between nodes;

The input of the last line is a positive integer, indicating the specified broadcast node serial number;

Output description:

Output an integer, indicating that the sending node needs to wait at least the length of time to receive all response messages.

Example 1:

enter

5 7

2 1

1 4

2 4

2 3

3 4

3 5

4 5

2

output

4

92.【Breadth-first traversal of binary tree】

There is a binary tree, each node is identified by a capital letter (up to 26 nodes). There are two sets of letters, respectively representing the results of post-order traversal (left child -> right child > parent node) and in-order traversal (left child-parent node-right child), please output the result of hierarchical traversal.

Enter a description:

The input is two strings, which are the subsequent traversal and inorder traversal results of the binary tree, respectively.

Output description:

Output the level traversal result of the binary tree

Example 1:

enter:

          CBEFDA CBAEDF

output:

        ABDCEF

93.【Find the minimum sum of all integers in a string】

The input string s outputs the minimum sum of all integers contained in s,
  illustrate:
  1 The string s only contains a~z, A~Z, +, -,
  2. Legal integers include positive integers, one or more 0-9, such as: 0,2,3,002,102
  3. Negative integers, starting with a negative sign, and the number part consists of one or more 0-9, such as -2,-012,-23,-00023
  Input description: a string containing numbers
  Output description: the minimum sum of all integers
  Example:
    enter:
      bb1234aa
   output
      10
   enter:
      bb12-34aa
   output:
      -31

94.【Seek the maximum number of teams that can be dispatched】

 Example 1:

enter:

5

3 1 5 7 9

8

output:

3

95.【Number reverse printing】

 96【Hot Pot】

97.【Looking for a parking space】

98.【Sensitive field encryption】

99.【String Statistics】 

 100.【Jiugongge button】

 

 101.【Counting Game】

题目描述
100个人围成一圈,每个人有一个编码,编号从1开始到100.他们从1开始依次报数,报到为M的人自动退出圈圈,然后下一个人接着从1开始报数,直到剩余的人数小于M。请问最后剩余的人在原先的编号为多少?例如输入M=3时,输出为:“58,91”,输入M=4时,输出为: “34,45, 97”。
如果m小于等于1, 则输出“ERROR!”;
如果m大于等于100,则输出“ERROR!”;

示例
输入
3
输出
58,91

102.【叠积木】

103.【工号不够用了怎么办】

 104.【构成的正方形数量】

 【构成正方形数量】输入N个互不相同的二维整数坐标,求这N个坐标可以构成的正方形数量。(内积为零的的两个向量垂直)
输入描述:
第一行输入为N,N代表坐标数量,N为正整数。N<=100之后的K行输入为坐标xy以空格分隔,xy为整数,-10<=x,y<=10
输出描述:
输出可以构成的正方形数量。
示例1:输入
3
1 3
2 4
3 1
输出
0

105.【最长连续子序列】

 106.【根据某条件聚类最少交换次数】

给出数字K,请输出所有结果小于K的整数组合到一起的最少交换次数。

组合一起是指满足条件的数字相邻,不要求相邻后在数组中的位置。

数据范围

-100 <=K <= 100

-100 <= 数组中数值 <= 100

输入描述;

第一行输入数组:1 3 1 4 0

第二行输入K数值:2

输出描述;

第一行输出最少较好次数:1

备注:

小于2的表达式是 1 1 0,共三种可能将所有符合要求数字组合在一起,最少交换1次

示例1:

输入

1 3 1 4 0

2

输出

1

107.【跳格子游戏】

标题:跳格子游戏 | 时间限制:1秒 | 内存限制:262144K | 语言限制:不限

地上共有N个格子,你需要跳完地上所有的格子,但是格子间是有强依赖关系的,跳完前一个格子后,后续的格子才会被开启,格子间的依赖关系由多组steps数组给出,steps[0]表示前一个格子,steps[1]表示steps[0]可以开启的格子:

比如[0,1]表示从跳完第0个格子以后第1个格子就开启了,比如[2,1],[2,3]表示跳完第2个格子后第1个格子和第3个格子就被开启了

请你计算是否能由给出的steps数组跳完所有的格子,如果可以输出yes,否则输出no

说明:

1.你可以从一个格子跳到任意一个开启的格子

2.没有前置依赖条件的格子默认就是开启的

3.如果总数是N,则所有的格子编号为[0,1,2,3…N-1]连续的数组

输入描述:

输入一个整数N表示总共有多少个格子,接着输入多组二维数组steps表示所有格子之间的依赖关系

输出描述:

如果能按照steps给定的依赖顺序跳完所有的格子输出yes

否则输出no

示例1

输入

3

0 1

0 2

输出

yes

说明

总共有三个格子[0,1,2],跳完0个格子后第1个格子就开启了,跳到第0个格子后第2个格子也被开启了,按照0->1->2或者0->2->1的顺序都可以跳完所有的格子

示例2

输入

2

1 0

0 1

输出

no

说明

总共有2个格子,第1个格子可以开启第0格子,但是第1个格子又需要第0个格子才能开启,相互依赖,因此无法完成

示例3

输入

6

0 1

0 2

0 3

0 4

0 5

输出

yes

说明

总共有6个格子,第0个格子可以开启第1,2,3,4,5个格子,所以跳完第0个格子之后其他格子都被开启了,之后按任何顺序可以跳完剩余的格子

示例4

输入

5

4 3

0 4

2 1

3 2

输出

yes

说明

After jumping the 0th grid, you can open the grid 4, after jumping the grid 4, you can open the grid 3, after jumping the grid 3, you can open the grid 2, after jumping the grid 2, you can open the grid 1, according to 0->4->3->2- >1 so that all grids are skipped

Example 5

enter

4

1 2

1 0

output

yes

illustrate

There are a total of 4 grids [0,1,2,3]. Grid 1 and grid 3 have no preconditions, so they are enabled by default. Grid 1 can enable grid 0 and grid 2, so after jumping to grid 1, all grids can be enabled. So you can skip all grids

108.【MVP Battle】

Title description: In the star basketball competition, the powerful space team, I hope everyone can get the MVP. The condition for the MVP is that the winners with the highest points in a single game can be tied, so Team Cosmos decided to put as many players on the field as possible during the game, and let all scorers have the same score. However, every minute of the game can only be scored by one person.

Input description: Enter a number t in the first line, indicating the number of minutes scored (1<=t<=50), and t numbers in the second line, representing the score p of each minute (1<=p<=50)

Output description: Output the least MVP score when all the scoring players are MVPs.

example

Example 1

Input: 9

            5 2 1 5 2 1 5 2 1

Output: 6

Explanation: Example explanation: A total of 4 people scored, each with 6 points

        5+1

        5+1

        5+1

        2+2+2

109.【The location of the school】

Title description: In order to solve the problem of skyrocketing students in the new semester, Xiaole Village will build a school. Considering the safety of students going to school, it is necessary for all students to have the shortest distance from their home to school. Assuming that the school and all the students’ homes are in a straight line, where should the school be built so that the sum of the distances from the school to each student’s home is the shortest?

Input description: The first line of input is an integer N (1<=N<=1000), indicating that there are N households.

                The second line of input is a genus ni (0<=ni<=10000), indicating the location of each household, and the locations of all households are different.

Output description: Output one line, an integer, indicating the location of the school you determined. If there are multiple locations with the same value, output the location with the smallest value.

example

Example 1:

Input: 5

        0 20 40 10 30

Output: 20

说明:20到各个家庭的距离分别为20 0 20 10 10,总和为60,最小

示例2:

输入:1

         20

输出:20

说明:只有一组数据,20到20距离最小,为0.

示例3:

输入:2

          0 20

输出:0

说明:虽然,有多个地方可以选,但是0数值最小

110.【组装新的数组】

题目描述:给你一个整数M和数组N,N中的元素为连续整数,要求根据N中的元素组装成新的数据R,组装原则:

        1.R中元素总和加起来等于M

        2.R中的元素可以从N中重复选取

        2.R中的元素最多只能有1个不在N中,且比N中的数字都要小(不能为负数)

请输出:数组R一共有多少组装办法

输入描述:第一行输入是连续数组N,采用空格分割

        第二行输入数字M

输出描述:输出的是组装办法数量,int类型

补充说明:1<=N.length<=30

                1<=N.length<=1000

示例

示例1:

输入:2

           5

输出:1

说明:只有1中组装办法,就是[2,2,1]

示例2:

输入:2 3

            5

输出:2

说明:一共2种组装办法,分别是[2,2,1],[2,3]

Guess you like

Origin blog.csdn.net/nanzhanfei/article/details/124895671