Question 1:
Question: 50*50 in the grid to play with the snake. The N-step twisting operation is provided to determine that the snake will be suspended in the first step. (Snake initially goes East)
Problem solving process:
1. the method at the beginning is: to speed up the process, only the coordinates of the header and tail are saved, and then the direction of the tail is saved. Each move starts first, then the tail moves in the previous direction until the direction needs to be changed (moving in the previous direction will hit the wall or go to a place where map [x] [Y] = 0 ).. This turns out to be wrong. It is possible that the tail will continue to go to a place where map [x] [Y] = 0, but the direction does not need to be changed .. Lucky! We got 60 points.
2. AC algorithm: Save the coordinates of all vertices and simulate them .. For this small data problem, you don't have to pursue speed. AC is king.
Question 2:
Given n Different Integer Points on the plane, count the number of Cartesian triangles whose edges are parallel to the coordinate axes Based on the given points as the vertex. 0 <n ≤ 100,000
Problem solving process:
1. First, we must make a discretization and sort the order .. Then we can enumerate right-angle vertices and calculate the following four right-angle triangles:
X xxx
Xx
Xxx x
Then we need to use the number a of vertices on the positive left, the number B of vertices on the right, the number C of vertices on the top, and the number D of vertices on the bottom.
In the preceding four cases, the numbers are a * C, B * C, B * D, and a * d, respectively. The merge operation is (A + B) * (C + D )..
Therefore, you only need to calculate the number of points on each straight line, and then find the two lines that belong to each point, and multiply them to the ans.
The initial score is 100. It seems that there will be a better way to deal with it. It seems that my method is slow .. The constant is large.
Question 3:
Description:
Alan is a typist in a confidential department. for confidentiality purposes, the keyboard used by this Department for password input is specially designed. There is no number key on the keyboard, but there are only the following six keys: swap0, swap1, up, down, left, right. To illustrate the functions of these six keys, we first define the numbers of the six positions in the input area, which are 1, 2, 3, 4, 5, 6 from left to right. The roles of each key are listed below:
Swap0: Press swap0, And the cursor position remains unchanged. Switch the number at the cursor position to the number at the position 1 in the input area (the first number on the left. If the cursor is already in the No. 1 position of the input area, the number of the input area remains unchanged after the swap0 key is pressed;
Swap1: Press swap1, And the cursor position remains unchanged. Switch the number at the cursor position to the number at the position 6 in the input area (the sixth digit from the left. If the cursor is already in the No. 6 Position of the input area, the number of the input area remains unchanged after the swap1 key is pressed;
Up: Press up. The cursor position remains unchanged. Add the number at the cursor position to 1 (unless the number is 9 ). For example, if the number of the cursor is 2, after the cursor is up, the number of the cursor is 3. If the number is 9, after the cursor is up, the number remains unchanged, and the cursor position remains unchanged;
Down: press down. The cursor position remains unchanged. Reduce the number at the cursor position by 1 (unless the number is 0). If the number is 0, press down and the number remains unchanged, the cursor position remains unchanged;
Left: press left. move the cursor to the left position. If the cursor is already at position 1 (the first position on the left) in the input area,
The cursor does not move;
Right: press right. Move the cursor to the right position. If the cursor is already in position 6 of the input area (sixth from the left)
The cursor does not move.
Of course, in order for such a keyboard to function, an initial password with a length of 6 will always appear at random in the input area before each password entry, and the cursor will appear at the position 1. When the above six special keys are skillfully used, the target password can be obtained, and the cursor is allowed to stop at any position.
Now, Alan has a 6-digit password. Write a program to find the minimum number of times required to enter a password.
Problem solving process:
1. This question seems to have been searched only by BFs... Two-way BFS is faster, but it still cannot exceed 000000 of the limit data. It takes about 3 seconds .. The instructor's test data is a little weak .. The bare BFS can only run for 0.8 s at most .. Then a pruning operation is added to process the maximum and minimum numbers of the target. If the current number is not between them, no up or down operation is required. Instantly changed to 0.2 S ..
2. There are two more incorrect pruning: if the current number is equal to the number on the corresponding digit of the target, the value does not need to be changed .. The left-shift operation is also abandoned .. Of course they are all wrong .. However, I am too weak. When I submitted the Tle for n times in poj1184, I added the second pruning error and output 59 directly in 000000 999999, and the result was 900 ms AC.
3. If you have any good pruning skills, please submit them to us.
Divisor (6) day2