This article is a mirror article of machine translation, please click here to jump to the original article.

View: 19688|Reply: 5

[Source] 2014 "Blue Bridge Cup" preliminary test questions

[Copy link]
Posted on 10/16/2014 3:34:10 PM | | | |
See the code answer at the bottom:
You must have heard this story. The king admired the minister who invented chess and asked him what he would pay for, and the minister said: Please be in the first place1A checkerboard is placed1Grain of wheat, in the house2A checkerboard is placed2Grain of wheat, in the house3A checkerboard is placed4Grain of wheat, in the house4A checkerboard is placed8wheat,......The number of the latter square is twice as high as the previous one until all the checkerboard squares are played (common in chess64Grid).
The king thought he just wanted a sack of wheat and laughed.
It was impossible to calculate accurately under the conditions of the time, but the estimates were surprising: even if the whole world was covered with wheat, it would not be enough!
Please use the computer to calculate exactly how many grains of wheat you need.
     Please write code to output the result directly.





Previous:The top ten taboos for college students that I just saw
Next:Java Chapter 1 Knowledge Points
 Landlord| Posted on 10/16/2014 3:34:24 PM |
* Outputs all substrings of a string (substrings do not include empty strings and the string itself),
* For example: all substrings of the string "abc": "a", "b", "c", "ab", "bc".
* All substrings of the string "abcd": "a", "b", "c", "d", "ab", "bc", "cd", "abc", "bcd".
 Landlord| Posted on 10/16/2014 3:35:14 PM |
Xiaomei likes to play with blocks. She stacked the blocks one by one into boxes of different heights.Look, I built a wall!She told her eldest sister Xiaoliang.Well, you should build all the blocks the same height. So you build a real wall.She replied. After thinking for a while, Xiaomei thought she was right. Then, she began to rearrange the blocks, one after another, and finally, all the blocks were the same height. But Xiaomei is lazy, she wants to move only the minimum number of blocks to make all the blocks the same height. Can you help her?


Enter a description:
The input contains multiple data collections. The first row of each data set is an integern, which represents the number of columns of the building blocks of Xiaomei. The second line containsnintegers, each representing the height of each block columnhi, indicates that there is in the columnhi blocks. Assumed1≤n≤501≤hi≤100。
The total number of blocks is divisible by the number of columns. Therefore, it is guaranteed that each column will be stacked at the same height.
The input ends with 0, and 0 is not used as input data.
Output Description:
For each dataset, print out the serial number of the dataset, see the output example. Then print the text "The minimum number of moves is k.". Here, k refers to the minimum number of times it takes to move these blocks to the same height.
Output one empty row after each dataset.
Input example:
6
5 2 4 1 7 5
0
Output sample
Set #1
The minimum number of moves is 5.

 Landlord| Posted on 10/16/2014 3:35:31 PM |
Robot walking
A certain children's palace introduced a number of robot trolleys. You can accept pre-entered instructions and act according to them. The basic movements of the trolley are very simple, there are only 3 types: turn left (marked as L), turn right (marked as R), and walk forward a few centimeters (directly mark the number).

    For example, we can enter the following command on the trolley:

    15L10R5LRR10R20

    Then, the car goes straight for 15 cm, turns left, then walks 10 cm, and then turns right,...

    It is not difficult to see that for this command string, the car returned to the starting point.

    Your task is: write a program, let the user input instructions, and the program outputs the straight-line distance between the trolley position after each instruction is executed and the position of the trolley before the command is executed.

[Input and output format requirements]

    The user first enters an integer n(n<100), which means that there will be n instructions next.

    Next, enter n instructions. Each instruction consists only of L, R and numbers (numbers are integers between 0~100)

    Each instruction must be no longer than 256 characters long.

    The program outputs n lines of results.

    Each result represents the straight-line distance of the trolley before and after executing the corresponding command. Require rounding to 2 decimal places.

    For example: User input:
5
L100R50R10
3LLL5RR4L12
LL
100R
5L5L5L5

    Then the program outputs:
102.96
9.06
0.00
100.00
0.00
 Landlord| Posted on 10/16/2014 3:36:08 PM |
Guess the numbers game, the rules of the game are as follows:
1. A player gives one0~9integer number
2. Three players guess the number in turn, and each person guesses once for one round
3. After one round, if a player guesses correctly, the game ends, and if no player guesses correctly, another round is played until a player guesses correctly.
Write code that simulates a complete game process (with all players).
(Prompt:JavalanguageMath.random()The function can return a function greater than 0and less than1random number)
The reference output is as follows (the result will be different for each run):


 Landlord| Posted on 10/16/2014 3:36:24 PM |
[Divide the cards equally]
There are N piles of cards, numbered 1,2,...,n. There are several cards on each pile, but the total number of cards must be a multiple of n. You can take several cards on any pile and move them.
The rules for moving cards are: cards taken on the number 1 can only be moved to the pile with the number 2; Cards taken on the pile numbered n can only be moved to the pile numbered n-1; Cards taken from other piles can be moved to the adjacent left or right pile. Now it is required to find a way to make the same number of cards on each pile with the least number of moves.
For example: n=4, 4 piles of cards are: (1) 9 (2) 8 (3) 17 (4) 6 Move three times to achieve the goal: take 4 cards from (3) and put them on (4) then from (3) to (2) and then from (2) to (1)


Please enter the number of heaps n:
4
Please enter the initial value for each heap:
9 8 17 6

Output:
There are 4 piles of 10 each
Minimum moves: 3 times
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com