 Light The Square

There is a new square been built in hangzhou,now in order to light the whole square in the night,it must need a lots of lights.
The government is lack of finance,so they want the the number of lights to be least.So they ask you to help.
To simplify the problem,the square can be see as a n��m rectangle. And lights are placed in this grids.If one grid has a light,its left, up, right, down grid can also be bright.Given m and n,Write a program to calculate the mininum number of lights.
Input
The input file will contain one or more test cases,Each test case contains of one line containing two integers 0<n<150 and 0<m<9,separated by a space.The input file is end with m=n=0.and this case should not proceed.
Output
For each test case,output one line "The square S need(s) L lights.",where S is the test case,L is the mininum number of this square.
Sample Input
1 1
2 2
3 3
0 0Sample Output
The square 1 need(s) 1 lights.
The square 2 need(s) 2 lights.
The square 3 need(s) 3 lights.
To Bet or Not To Bet _course
20171017Description Alexander Charles McMillan loves to gamble, and during his last trip to the casino he ran across a new game. It is played on a linear sequence of squares as shown below. ![](http://poj.org/images/1644_1.jpg) A chip is initially placed on the Start square. The player then tries to move the chip to the End square through a series of turns, at which point the game ends. In each turn a coin is fl ipped: if the coin is heads the chip is moved one square to the right and if the coin is tails the chip is moved two squares to the right (unless the chip is one square away from the End square, in which case it just moves to the End square). At that point, any instruction on the square the coin lands on must be followed. Each instruction is one of the following: 1. Move right n squares (where n is some positive integer) 2. Move left n squares (where n is some positive integer) 3. Lose a turn 4. No instruction After following the instruction, the turn ends and a new one begins. Note that the chip only follows the instruction on the square it lands on after the coin flip. If, for example, the chip lands on a square that instructs it to move 3 spaces to the left, the move is made, but the instruction on the resulting square is ignored and the turn ends. Gambling for this game proceeds as follows: given a board layout and an integer T, you must wager whether or not you think the game will end within T turns. After losing his shirt and several other articles of clothing, Alexander has decided he needs professional helpnot in beating his gambling addiction, but in writing a program to help decide how to bet in this game. Input Input will consist of multiple problem instances. The first line will consist of an integer n indicating the number of problem instances. Each instance will consist of two lines: the first will contain two integers m and T (1 <= m <= 50, 1 <= T <= 40), where m is the size of the board excluding the Start and End squares, and T is the target number of turns. The next line will contain instructions for each of the m interior squares on the board. Instructions for the squares will be separated by a single space, and a square instruction will be one of the following: +n, n, L or 0 (the digit zero). The first indicates a right move of n squares, the second a left move of n squares, the third a loseaturn square, and the fourth indicates no instruction for the square. No right or left move will ever move you off the board. Output Output for each problem instance will consist of one line, either Bet for. x.xxxx if you think that there is a greater than 50% chance that the game will end in T or fewer turns, or Bet against. x.xxxx if you think there is a less than 50% chance that the game will end in T or fewer turns, or Push. 0.5000 otherwise, where x.xxxx is the probability of the game ending in T or fewer turns rounded to 4 decimal places. (Note that due to rounding the calculated probability for display, a probability of 0.5000 may appear after the Bet for. or Bet against. message.) Sample Input 5 4 4 0 0 0 0 3 3 0 1 L 3 4 0 1 L 3 5 0 1 L 10 20 +1 0 0 1 L L 0 +3 7 0 Sample Output Bet for. 0.9375 Bet against. 0.0000 Push. 0.5000 Bet for. 0.7500 Bet for. 0.8954
The Umbrella Problem: 2054 _course
20171011Description "Forget it," Garret complained, throwing down the controller to his PlayStation VIII, "this level is impossible." He had just "died" for the 17th time on level 54 of the game "Lemmings 9: Lost in Space". "No it isn't," his brother Ferret replied, "and I can prove it." Ferret pulled his PlaySkool PDA from the back pocket of his Levi's Huggies. "First, picture the level as a rectangular grid." Ferret punched a few of the buttons on his PDA and a rectangle appeared as he described. "Your character, a Lemming holding an umbrella, starts at the top of this rectangle. His goal is to reach the bottom without dying." "I know that, you weasel, but what about the laser guns?" Garret whined. "The name is Ferret, and I was just getting to that. If we represent the level as a rectangular grid, then the Lemming can occupy one square and each laser gun can occupy a square. Remember the laser guns are cyclic: they all shoot up the first turn, right the second turn, down the third turn, left the fourth turn, and then repeat the sequence." "But you're forgetting the pits of lava!" Garret exclaimed. "You didn't let me finish. Each pit of lava also occupies a square. And each plot of grass, the Lemming's destination, can also occupy a square. Then, it's just a matter of manipulating the Lemming and laser beams in a series of turns to determine if it is possible for the Lemming to reach the bottom without 'dying'." "You think you're so smart, Ferret, let's see if you can explain that again in a clear, concise way." "Certainly": The level will consist of a grid of squares. The way each laser beam and the Lemming moves can be described in "turns". To determine if the Lemming can reach the bottom of the level without dying, Ferret devised some rules: Each turn will consist of two steps: First, the laser guns will "fire" and maintain until the end of the turn, a beam in a direction dependent on the number of the turn. On the first turn, each laser gun will shoot up (all squares directly above a laser gun are "unsafe" and cannot be occupied by the Lemming); on the second turn, each laser gun will shoot right; on the third turn, each laser gun will shoot down; on the fourth turn, each laser gun will shoot left; on the fifth turn, the sequence will repeat. Example: Column 01234 R 0 L < The Lemming will always start in a column on row 0 o 1  In this example, on the first turn, the laser beam w 2 S  will occupy squares (3,0),(3,1); second turn, (4,2); 3  third turn, (3,3),(3,4),(3,5),(3,6); fourth turn, 4  (0,2),(1,2),(2,2); fifth turn (repeating), (3,0),(3,1), etc. 5  (squares are represented using (column,row) notation) 6GPPGG< The pits of lava and grass squares will always be in the last row Second, the Lemming will always move one row down, but to any one of three columns: one column to the left, one column to the right, or remain in the same column. In the above example, on the first turn the Lemming (L) could move to square (1,1), (2,1), or (3,1) (if he moved to (3,1), though, he would die because of the laser beam). However, on any turn the Lemming cannot move outside of the grid (i.e., he cannot move to column 1, or to a column number equal to the number of columns). The level is considered "possible" if the Lemming can reach any "grass" square without dying after a series of turns. The Lemming will die if at any point he occupies the same square as a laser gun, its beam, or a pit of lava. This includes: The Lemming moving into a square a pit of lava occupies, The Lemming moving into a square a laser gun occupies, The Lemming moving into a square a laser beam occupies (even if it is a grass square!), A laser gun firing a beam into a square the Lemming occupies Input Input to this problem will consist of a (nonempty) series of up to 100 data sets. Each data set will be formatted according to the following description, and there will be no blank lines separating data sets. Each data set will describe the starting conditions of the level. A single data set has the following components: Start line  A single line, "START x y", where 0 < x < 10 and x is the number of columns in the grid representing the level and 1 < y < 10 and y is the number of rows in the grid representing the level. The next y lines will represent the rows of the level, starting with row 0 (the top). Each line will consist of x letters. The letters will represent components of the level as follows: L  Lemming (there will only be one 'L' per data set, and it will always be in row 0) S  laser gun (these squares will never be in the final row) P  pit of lava (these squares will always be in the final row) G  grass (these squares will also always be in the final row) O  "empty" square of air End line  A single line, "END". Following the final data set will be a single line, "ENDOFINPUT". Output Output for each data set will be exactly one line. The line will either be "FERRET" or "GARRET" (both all caps with no whitespace leading or following). "FERRET" will appear if the Lemming can make it safely (without dying) to any grass square at the bottom of the level after a series of turns. "GARRET" will be output for a data set if it fails to meet the criteria for a "FERRET" line.
Grandpa's Other Estate _course
20171011Description From our previous contest, we know that Kamran the Believer inherited many of his grandpa抯 belongings. Apparently, his grandpa had been a mathematician in his life with interests in puzzle solving, since he has made Kamran solve another programming problem! Grandpa had a big garden with many valuable walnut trees. He has written in his will that Kamran can inherit one piece of square shaped land of a given size in the garden, such that its sides be parallel to the x and y axes. Taking advantage of the fact that no other restrictions have been mentioned in the will, Kamran wants to choose the land in which the most number of trees lie. Kamran is too wealthy now and thus too lazy to spend time and solve another algorithmic problem. He has hired you to solve this problem for him. You are given the location of all trees in the big garden and the size of the land to choose. You are to write a program to find out where to choose the land so that the most number of trees lie in it. You may consider trees as points in the plane and the land as a square. You are to find the position of the square such that it includes as many points as possible. Note that the points on the border of the square are considered to be inside it. Input The first line of the input file contains a single integer t (1 <= t <= 10), the number of test cases, followed by the input data for each test case. The first line of each test case contains an integer n (1 <= n <= 100), the number of trees, and an integer r (1 <= r <= 1000), the length of the land's side, followed by n lines, each containing two integers x and y (0 <= x, y <= 100,000) representing the coordinates of a walnut tree. Note that all coordinates are pairwise distinct. Output There should be one line per test case containing the maximum number of trees that Kamran can own. Sample Input 1 3 1 1 2 2 1 4 3 Sample Output 2
Holedox Moving _course
20171015Description During winter, the most hungry and severe time, Holedox sleeps in its lair. When spring comes, Holedox wakes up, moves to the exit of its lair, comes out, and begins its new life. Holedox is a special snake, but its body is not very long. Its lair is like a maze and can be imagined as a rectangle with n*m squares. Each square is either a stone or a vacant place, and only vacant places allow Holedox to move in. Using ordered pair of row and column number of the lair, the square of exit located at (1,1). Holedox's body, whose length is L, can be represented block by block. And let B1(r1,c1) B2(r2,c2) .. BL(rL,cL) denote its L length body, where Bi is adjacent to Bi+1 in the lair for 1 <= i <=L1, and B1 is its head, BL is its tail. To move in the lair, Holedox chooses an adjacent vacant square of its head, which is neither a stone nor occupied by its body. Then it moves the head into the vacant square, and at the same time, each other block of its body is moved into the square occupied by the corresponding previous block. For example, in the Figure 2, at the beginning the body of Holedox can be represented as B1(4,1) B2(4,2) B3(3,2)B4(3,1). During the next step, observing that B1'(5,1) is the only square that the head can be moved into, Holedox moves its head into B1'(5,1), then moves B2 into B1, B3 into B2, and B4 into B3. Thus after one step, the body of Holedox locates in B1(5,1)B2(4,1)B3(4,2) B4(3,2) (see the Figure 3). Given the map of the lair and the original location of each block of Holedox's body, your task is to write a program to tell the minimal number of steps that Holedox has to take to move its head to reach the square of exit (1,1). ![](http://poj.org/images/1324_1.jpg) Input The input consists of several test cases. The first line of each case contains three integers n, m (1<=n, m<=20) and L (2<=L<=8), representing the number of rows in the lair, the number of columns in the lair and the body length of Holedox, respectively. The next L lines contain a pair of row and column number each, indicating the original position of each block of Holedox's body, from B1(r1,c1) to BL(rL,cL) orderly, where 1<=ri<=n, and 1<=ci<=m,1<=i<=L. The next line contains an integer K, representing the number of squares of stones in the lair. The following K lines contain a pair of row and column number each, indicating the location of each square of stone. Then a blank line follows to separate the cases. The input is terminated by a line with three zeros. Note: Bi is always adjacent to Bi+1 (1<=i<=L1) and exit square (1,1) will never be a stone. Output For each test case output one line containing the test case number followed by the minimal number of steps Holedox has to take. "1" means no solution for that case. Sample Input 5 6 4 4 1 4 2 3 2 3 1 3 2 3 3 3 3 4 4 4 4 2 3 1 3 1 4 2 4 4 2 1 2 2 3 4 4 2 0 0 0 Sample Output Case 1: 9 Case 2: 1
Magic Bitstrings _course
20171016Description A bitstring, whose length is one less than a prime, might be magic. 1001 is one such string. In order to see the magic in the string let us append a nonbit x to it, regard the new thingy as a cyclic string, and make this square matrix of bits each bit 1001 every 2nd bit 0110 every 3rd bit 0110 every 4th bit 1001 This matrix has the same number of rows as the length of the original bitstring. The mth row of the matrix has every mth bit of the original string starting with the mth bit. Because the enlarged thingy has prime length, the appended x never gets used. If each row of the matrix is either the original bitstring or its complement, the original bitstring is magic. Input Each line of input (except last) contains a prime number p <= 100000. The last line contains 0 and this line should not be processed. Output For each prime number from the input produce one line of output containing the lexicographically smallest, nonconstant magic bitstring of length p1, if such a string exists, otherwise output Impossible. Sample Input 5 3 17 47 2 79 0 Sample Output 0110 01 0010111001110100 0000100001101010001101100100111010100111101111 Impossible 001001100001011010000001001111001110101010100011000011011111101001011110011011
Flip Game _course
20171102Problem Description Flip game is played on a square N*N field with twosided pieces placed on each of its N^2 squares. One side of each piece is white and the other one is black and each piece is lying either it's black or white side up. The rows are numbered with integers from 1 to N upside down; the columns are numbered with integers from 1 to N from the left to the right. Sequences of commands (xi, yi) are given from input, which means that both pieces in row xi and pieces in column yi will be flipped (Note that piece (xi, yi) will be flipped twice here). Can you tell me how many white pieces after sequences of commands? Consider the following 4*4 field as an example: bwww wbww wwbw wwwb Here "b" denotes pieces lying their black side up and "w" denotes pieces lying their white side up. Two commands are given in order: (1, 1), (4, 4). Then we can get the final 4*4 field as follows: bbbw bbwb bwbb wbbb So the answer is 4 as there are 4 white pieces in the final field. Input The first line contains a positive integer T, indicating the number of test cases (1 <= T <= 20). For each case, the first line contains a positive integer N, indicating the size of field; The following N lines contain N characters each which represent the initial field. The following line contain an integer Q, indicating the number of commands; each of the following Q lines contains two integer (xi, yi), represent a command (1 <= N <= 1000, 0 <= Q <= 100000, 1 <= xi, yi <= N). Output For each case, please print the case number (beginning with 1) and the number of white pieces after sequences of commands. Sample Input 2 4 bwww wbww wwbw wwwb 2 1 1 4 4 4 wwww wwww wwww wwww 1 1 1 Sample Output Case #1: 4 Case #2: 10
Cubic EightPuzzle _course
20170122Description Let’s play a puzzle using eight cubes placed on a 3 × 3 board leaving one empty square. Faces of cubes are painted with three colors. As a puzzle step, you can roll one of the cubes to a adjacent empty square. Your goal is to make the specified color pattern visible from above by a number of such steps. The rules of this puzzle are as follows. Coloring of Cubes: All the cubes area colored in the same way as shown in Figure 1. The opposite faces have the same color. Figure 1: Coloring of a cube Initial Board State: Eight cubes are placed on the 3 × 3 board leaving one empty square. All the cubes have the same orientation as shown in Figure 2. As shown in the figure, squares on the board are given x and y coordinates, (1, 1), (1, 2), …, and (3, 3). The position of the initially empty square may vary. Figure 2: Initial board state Rolling Cubes: At each step, we can choose one of the cubes adjacent to the empty square and roll it into the empty square, leaving the original position empty. Figure 3 shows an example. Figure 3: Rolling a cube Goal: The goal of this puzzle is to arrange the cubes so that their top faces form the specified color pattern by a number of cube rolling steps described above. Your task is to write a program that finds the minimum number of steps required to make the specified color pattern from the given initial state. Input The input is a sequence of datasets. The end of the input is indicated by a line containing two zeros separated by a space. The number of datasets is less than 16. Each dataset is formatted as follows. x y F11 F21 F31 F12 F22 F32 F13 F23 F33 The first line contains two integers x and y separated by a space, indicating the position (x, y) of the initially empty square. The values of x and y are 1, 2, or 3. The following three lines specify the color pattern to make. Each line contains three characters F1j, F2j, and F3j, separated by a space. Character Fij indicates the top color of the cube, if any, at the position (i, j) as follows: B: Blue, W: White, R: Red, E: the square is Empty. There is exactly one ‘E’ character in each dataset. Output For each dataset, output the minimum number of steps to achieve the goal, when the goal can be reached within 30 steps. Otherwise, output “1” for the dataset. Sample Input 1 2 W W W E W W W W W 2 1 R B W R W W E W W 3 3 W B W B R E R B R 3 3 B W R B W R B E R 2 1 B B B B R B B R E 1 1 R R R W W W R R E 2 1 R R R B W B R R E 3 2 R R R W E W R R R 0 0 Sample Output 0 3 13 23 29 30 1 1
Zerg Rush!!! _course
20171030Problem Description A typical strategy in the game Starcraft is to mass up large amounts of lowtier units such as Zerglings, then throw them at your opponent and laugh maniacally as they overwhelm any opposition. However, when both players opt for the same strategy, the result can often become...quick, brutal and messy. Sadly, the game only allows for up to 400 Zerglings per player. In this problem, however, you will simulate games that could have more than 400 Zerglings. The map on which Zerg rushes occur is represented by a NxN grid. Each Zergling occupies a grid square and no two Zerglings ever occupy the same grid square. Each Zergling has a certain number of hit points which starts off as 35. Its attack value is 5 plus the attack upgrade of the player that controls it. When one Zergling attacks another, the damage incurred equals to the attack value of the attacking Zergling minus the armour upgrade of the player that owns the Zergling being attacked. The number of hit points of the Zergling that is attacked is reduced by the amount of the damage. Due to the inability of both players to manage their huge horde of Zerglings, the Zerglings make their decisions each turn using the following algorithm (Zerglings are not the brightest creatures, as you will see): * If there is an opponent Zergling in one of the 8 horizontally, vertically, or diagonally adjacent grid squares, the Zergling will attack it. A Zergling attacks at most one opponent each turn; see below for the tiebreaking rules. * Otherwise, if the other player has at least one Zergling remaining on the map, the Zergling will move to the horizontally, vertically, or diagonally adjacent square that is closest to the opponent's closest Zergling in terms of Manhattan distance. When more than one adjacent square is closest, the tiebreaking rules below are used. The Manhattan distance between two points is the sum of the differences in the x and y coordinates of the points. When the above rules could cause the Zergling to attack in more than one direction, or to move in more than one direction, the following tiebreaking rule is used. The Zergling will prefer the first direction starting with north going clockwise. That is, the directions in order of preference are north, northeast, east, southeast, etc. Once all Zerglings have made their decisions, all the attacks are conducted simultaneously and all the Zerglings with 0 or fewer hit points are marked as dead and removed from the map. Then all the movements of the Zerglings that didn't attack are conducted simultaneously. If the square to which a Zergling is moving is occupied by another Zergling that is not moving away in this turn, then the Zergling does not move. If two or more Zerglings try to move to the same grid square, then the Zergling in the northernmost row has the right of way and the other Zergling remains stationary. If there are multiple Zerglings in the northernmost row trying to move to the same grid square, then of these, the westernmost Zergling moves and the others remain stationary. Zerglings also have a remarkable regeneration rate. After each turn, all the Zerglings that are still alive and have less than 35 hitpoints will regain one hit point. Input The input file contains a number of test cases, ended by a case with N=0. Each case begins with N between 2 and 150, followed by 2 pairs of 2 integers between 0 and 3, the attack and armour upgrades of the first player, followed by the attack and armour upgrades of the second player. This is followed by the initial game map, where '.' denotes an empty square, '1' a Zergling belonging to the first player and '2' a Zergling belonging to the second player. On the map, north is up (i.e. towards the first row) and west is left (i.e. towards the first column). Finally, the test case provides the number t of turns for which the Zerg rush is to be simulated, which is an integer between 0 and 400, inclusive. Output For each input case, output the map after t turns in the same format as above. Print one empty line between the output for consecutive test cases. Sample Input 2 0 0 0 0 1. .. 0 2 0 0 0 0 1. .2 100 0 Sample Output 1. .. .. ..
Matrix Multiplication 矩阵乘法_course
20161226Description Many studies have been done on developing efficient algorithms to calculate matrix multiplication. But it remains as a hard topic today. In this problem you are to calculate the 2006th power of a square Boolean matrix where addition and multiplication are defined as follows: A B A + B 0 0 0 0 1 1 1 0 1 1 1 1 Truth Table of Addition A B AB 0 0 0 0 1 0 1 0 0 1 1 1 Truth Table of Multiplication Let A be a square matrix. The zeroth power of A is the identity matrix. The nth (n > 0) power of A is the product of A and its (n − 1)th power. Input The input contains multiple test cases. Each test cases consists of some lines: Line 1: Contains two integers K (K < 1000) and M (0 ≤ M ≤ 10K), indicating the dimension of the matrix is K × K and K + M elements of the matrix are 1’s. Lines 2 ~ M + 1: Each contains two integers i and j (0 ≤ i, j < K, i ≠ j), indicating the element in the (i + 1)th row and (j + 1)th column is 1. All elements on the primary diagonal of the matrix are 1’s. Output For each test case output one line containing the number of elements that are 1’s in the 2006th power of the given matrix. Sample Input 3 4 1 2 2 1 0 1 0 2 Sample Output 7
Warez Test _course
20161121Description Background Our hero Jimmy is deeply in love with Christine and wants to marry her. So far so good, but Christine is the daughter of Mr. Warez, the owner of nearly all the warehouses in town. And Mr. Warez will never let his daughter marry someone who is not working for him. The sad point is that you may not work for Mr. Warez at all if you do not know how to push boxes in a warehouse properly. So Jimmy has to pass the infamous "Warez Test" first. The Problem Jimmy receives a number of maps each showing the outline of a warehouse. A map consists of squares. On one square there can be a wall or a single box or it can be empty. One or more squares are marked as target squares. One square is marked as the starting point for Jimmy. Jimmy can move in four directions only: north, west, east and south. Jimmy can only move to an empty square or a square that is occupied by a box that can be pushed to the next square in the direction Jimmy is moving. This next square has to be empty which means that as a result of Jimmy moving one square at most one box can be moved exactly one square. By the way: Squares with a wall on it are not empty. . . The border of every map (the first and last row and first and last column of the map) is always occupied by walls. On every map there are always as many boxes as there are target squares and there is always at least one box. It is Jimmy's task to find the shortest way to push the boxes onto the target squares so that at the end each box stands on a target square. To determine if one way is shorter than the other only the moves of Jimmy are counted, no matter whether he thereby pushes a box or not. For every map it is guaranteed that there is exactly one shortest solution. Input The first line contains the number of scenarios (maps). For each map the first line contains the number of rows and columns of the map (both less than or equal to 15) separated by a blank. Then follows the map where 'X' indicates a square with a wall on it, 'T' indicates a target square and '.' indicates an empty square. In the next line follows the starting position of Jimmy (row and column separated by a blank), then follows the number of boxes in the line after that. The following lines contain the starting positions of the boxes (one box per line, row and column separated by a blank). The numbering of rows and columns starts with 0 in the upper left corner. Output The output for every scenario begins with a line containing "Scenario #i:", where i is the number of the scenario starting with 1. In the next line print the moves Jimmy has to make following the shortest possible solution. Print the letter 'n' for Jimmy moving north (up), 'w' for west (left), 'e' for east (right) and 's' for south (down). The output for each scenario should be followed by a blank line. Sample Input 2 8 6 XXXXXX X.T..X X....X X....X X....X X....X X....X XXXXXX 5 3 1 4 3 5 4 XXXX X.XX X..X XT.X XXXX 1 1 1 2 1 Sample Output Scenario #1: nnnenw Scenario #2: s
Rectangular Covering _course
20170102Description n points are given on the Cartesian plane. Now you have to use some rectangles whose sides are parallel to the axes to cover them. Every point must be covered. And a point can be covered by several rectangles. Each rectangle should cover at least two points including those that fall on its border. Rectangles should have integral dimensions. Degenerate cases (rectangles with zero area) are not allowed. How will you choose the rectangles so as to minimize the total area of them? Input The input consists of several test cases. Each test cases begins with a line containing a single integer n (2 ≤ n ≤ 15). Each of the next n lines contains two integers x, y (−1,000 ≤ x, y ≤ 1,000) giving the coordinates of a point. It is assumed that no two points are the same as each other. A single zero follows the last test case. Output Output the minimum total area of rectangles on a separate line for each test case. Sample Input 2 0 1 1 0 0 Sample Output 1
Knight Moves 骑士的移动问题_course
20161015Description A friend of you is doing research on the Traveling Knight Problem (TKP) where you are to find the shortest closed tour of knight moves that visits each square of a given set of n squares on a chessboard exactly once. He thinks that the most difficult part of the problem is determining the smallest number of knight moves between two given squares and that, once you have accomplished this, finding the tour would be easy. Of course you know that it is vice versa. So you offer him to write a program that solves the "difficult" part. Your job is to write a program that takes two squares a and b as input and then determines the number of knight moves on a shortest route from a to b. Input The input file will contain one or more test cases. Each test case consists of one line containing two squares separated by one space. A square is a string consisting of a letter (ah) representing the column and a digit (18) representing the row on the chessboard. Output For each test case, print one line saying "To get from xx to yy takes n knight moves.". Sample Input e2 e4 a1 b2 b2 c3 a1 h8 a1 h7 h8 a1 b1 c3 f6 f6 Sample Output To get from e2 to e4 takes 2 knight moves. To get from a1 to b2 takes 4 knight moves. To get from b2 to c3 takes 2 knight moves. To get from a1 to h8 takes 6 knight moves. To get from a1 to h7 takes 5 knight moves. To get from h8 to a1 takes 6 knight moves. To get from b1 to c3 takes 1 knight moves. To get from f6 to f6 takes 0 knight moves.
Obstructed Rook Circuits _course
20171012Description A board is a rectangular array of squares such as on a chessboard, with possibly some squares blocked off. A rook tour of a board is a path that visits each empty square of the board exactly once, moving at each step to an empty adjacent square (North, South, East or West but not diagonally). A rook tour is a rook circuit if it starts and ends on the same square. In the figures below, let the + symbol be the rook, and the X symbol be an obstruction. The following are descriptions of each figure: (a) is a board with no rook circuit, (b) and (c) give distinct rook circuits of the same board and (d) gives the unique (up to direction) rook circuit of another board. ![](http://poj.org/images/1670_1.jpg) Write a program, which takes as input the description of a board and either finds a rook circuit or determines that there is no rook circuit. Input Input consists of a sequence of board descriptions and starting points. The first line of the input is Nrows Ncols Nblocks StartX StartY where Nrows is the number of rows in the rectangular array, Ncols is the number of columns in the rectangular array, Nblocks is the number of blocked off squares on the board and (StartX, StartY) is the position on the board where the path is to start (and end). StartX and StartY are 0 based (StartX ranges from 0 to Ncols  1). Following the first line there are Nblocks lines giving the coordinates of the blocked off squares, one per line. The coordinates of these points are 0 based and are of the form X Y. The final line of each board description is a blank line. The last line of the input is line of 5 zeroes. Output If there is no rook circuit for the corresponding board, the output is a line "NO SOLUTION" followed by a blank line. Otherwise, the output is a sequence of the letters N, S, E, W giving the moves from the starting point to traverse a rook circuit and return to the starting point. (N indicates moving to the previous row, S moving to the next row, E moving to the next column and W moving to the previous column.) If more than 40 moves are required, the moves will be output 40 to a line (except possibly for the last line). The move output is to be followed by a blank line. Note that the same board may have several rook circuits. Your program need only find any one (correct) rook circuit. Sample Input 4 4 2 0 0 1 2 3 0 4 4 0 2 2 4 4 0 0 0 4 4 2 1 2 0 3 2 2 8 8 0 0 0 0 0 0 0 0 Sample Output NO SOLUTION NENWWWSESWSEEENW EEESWWSEESWWWNNN WNNESENESSSWWN EEEEEEESWWWWWWSEEEEEESWWWWWWSEEEEEESWWWW WWSEEEEEESWWWWWWWNNNNNNN
Squares _course
20161119Description A square is a 4sided polygon whose sides have equal length and adjacent sides form 90degree angles. It is also a polygon such that rotating about its centre by 90 degrees gives the same polygon. It is not the only polygon with the latter property, however, as a regular octagon also has this property. So we all know what a square looks like, but can we find all possible squares that can be formed from a set of stars in a night sky? To make the problem easier, we will assume that the night sky is a 2dimensional plane, and each star is specified by its x and y coordinates. Input The input consists of a number of test cases. Each test case starts with the integer n (1 <= n <= 1000) indicating the number of points to follow. Each of the next n lines specify the x and y coordinates (two integers) of each point. You may assume that the points are distinct and the magnitudes of the coordinates are less than 20000. The input is terminated when n = 0. Output For each test case, print on a line the number of squares one can form from the given stars. Sample Input 4 1 0 0 1 1 1 0 0 9 0 0 1 0 2 0 0 2 1 2 2 2 0 1 1 1 2 1 4 2 5 3 7 0 0 5 2 0 Sample Output 1 6 1
Homogeneous Squares _course
20161227Description Assume you have a square of size n that is divided into n × n positions just as a checkerboard. Two positions (x1, y1) and (x2, y2), where 1 ≤ x1, y1, x2, y2 ≤ n, are called “independent” if they occupy different rows and different columns, that is, x1 ≠ x2 and y1 ≠ y2. More generally, n positions are called independent if they are pairwise independent. It follows that there are n! different ways to choose n independent positions. Assume further that a number is written in each position of such an n × n square. This square is called “homogeneous” if the sum of the numbers written in n independent positions is the same, no matter how the positions are chosen. Write a program to determine if a given square is homogeneous! Input The input contains several test cases. The first line of each test case contains an integer n (1 ≤ n ≤ 1000). Each of the next n lines contains n numbers, separated by exactly one space character. Each number is an integer from the interval [−1000000, 1000000]. The last test case is followed by a zero. Output For each test case output whether the specified square is homogeneous or not. Adhere to the format shown in the sample output. Sample Input 2 1 2 3 4 3 1 3 4 8 6 2 3 4 0 0 Sample Output homogeneous not homogeneous
入门小白求解北京2004ACM的Square题_course
20160213入门小白开始啃题，然而啃不动（无奈摊手） 求大神帮忙解答（最好是有解释啦）(ฅ>ω<*ฅ) SquareTime Limit: 1000ms, Special Time Limit:2500ms, Memory Limit:32768KBTotal submit users: 177, Accepted users: 26Problem 10002 : No special judgementProblem descriptionGiven a square at [0, 1] * [0, 1] that has N points ( P1, P2, ..., PN ) in the square (you may assume that different points can be at the same position), we can connect the N points and the four corners of the square with some line segments so that through these segments any two of the N+4 points can reach each other (directly or indirectly). The graph length is defined as the total length of the line segments. When N points' positions are fixed, there must exist a way of connecting them, such that it will make the shortest graph length. We can use LEN (P1, P2, ..., PN) to record the graph length using this way of connecting. In this situation, LEN (P1, P2, ..., PN) is a function of P1, P2, ..., PN. When P1, P2, ..., PN change their positions, LEN (P1, P2, ..., PN) also changes. It's easy to prove that there exist some P1', P2', ..., PN' in the square such that LEN (P1', P2', ..., PN') is at its minimum. Given the initial positions of N points, your task is to find out N points P1", P2", ..., PN" in the square such that P1P1" + P2P2" + ... + PNPN" is minimum and LEN (P1", P2", ..., PN") = LEN (P1', P2', ..., PN') . You are requested to output the value of P1P1" + P2P2" + ... + PNPN", where PiPi" is the distance between Pi and Pi". ?￼ For example, Figure1 gives the initial position of P1 and the way of connecting to obtain LEN (P1). In Figure2, it gives the position of P1", which is at the center of the square, and the way of connecting to obtain LEN (P1"). It can be proved that LEN (P1") = LEN (P1?); your job is to output the distance between P1 and P1". InputThe input consists of several test cases. For each test case, the first line consists of one integer N (1 <= N <= 100), the number of points, and N lines follow to give the coordinates for every point in the following format: x y Here, x and y are float numbers within the value [0, 1]. A test case of N = 0 indicates the end of input, and should not be processed. OutputFor each test case, output the value of P1P1" + P2P2" + ... + PNPN". The value should be rounded to three digits after the decimal point. Sample Input1 0.2 0.5 2 0 0.5 0.5 0.5 0Sample Output0.300 0.500Judge Tips费马点 Problem SourceBeijing 2004![图片](https://imgask.csdn.net/upload/201602/13/1455372077_80112.png)
软件测试2小时入门
20181010本课程内容系统、全面、简洁、通俗易懂，通过2个多小时的介绍，让大家对软件测试有个系统的理解和认识，具备基本的软件测试理论基础。 主要内容分为5个部分： 1 软件测试概述，了解测试是什么、测试的对象、原则、流程、方法、模型； 2.常用的黑盒测试用例设计方法及示例演示； 3 常用白盒测试用例设计方法及示例演示； 4.自动化测试优缺点、使用范围及示例‘； 5.测试经验谈。
 43.19MB
智鼎(附答案).zip
20200422并不是完整题库，但是有智鼎在线2019年9、10、11三个月的试题，有十七套以上题目，普通的网申行测题足以对付，可以在做题时自己总结一些规律，都不是很难
 43KB
炉温系统的PID控制器设计——MATLAB程序
20180517本文主要研究的课题是：炉温系统的PID控制器设计研究 ，并且在MATLAB的大环境下进行模拟仿真。 (1)第一章 介绍课题的研究背景、意义以及发展现状。 (2)第二章 建立炉温系统数学模型 (3)第三
Java进阶高手课Java基础编程提升
20200427课程聚焦Java基础编程提升的核心知识点，以真实场景项目实战为导向，循序渐进，深入浅出的了解Java基础编程，讲解Java这门使用广泛的编程语言，助你能够游刃有余地游走在这些技术之中。
Python进阶Pandas数据分析库
20181218您观看课程学习后 免费入群领取【超全Python资料包+17本学习电子书】 Pandas是python中非常常用的数据分析库，在数据分析，机器学习，深度学习等领域经常被使用。本课程会讲解到pandas中最核心的一些知识点，包括Series以及DataFrame的构建，赋值，操作，选择数据，合并等等，以及使用pandas对文件进行读取和写入，使用pandas绘图等等。
Mysql数据库基础入门视频教程
20181024Mysql数据库基础入门视频课程：属于零基础Mysql数据库教程，从数据库的基本专业术语介绍到数据库软件的下载使用 一步一步带你安装MySql。SQL阶段你将学会如果使用数据定义语言DDL,数据操作语言DML,数据查询语言DQL 在学会各中查询语句之后,会带你学习数据的完整性, 掌握如果正确的向数据库中添加数据 以上掌握技能之后,将会带你学习如何进行多表操作,关系的建立,各种连接查询等. 常用函数,事务的学习,您将学到什么是事务的提交,回滚,并发操作及脏读,幻读. 最后视图,存储过程,索引的学习,将会带你掌握更高级的数据库技术.
 下载 BigDataFramwork实验手册.docx
 博客 webpack.config.js中的css样式、sass、打包抽离，浏览器加前缀（兼容），图片文件处理，ES6处理
 下载 嵌入式系统/ARM技术中的浅谈视频传输技术分析
 学院 PHP微信小程序鲜花礼品商城
 学院 JavaWeb手机数码购物商城毕业设计 大学生毕业设计教学视频
 学院 JavaWeb鲜花礼品购物商城毕业设计 大学生毕业设计教学视频
 博客 RFID技术在安防领域的应用
 学院 OpenGL进阶OSX版
 下载 Marvell PHY 88E1116R Datasheet 详细数据手册 寄存器配置
 博客 Java 异常的捕获与处理详解（一）(转载)
 学院 3小时快速学习计算机基础
 下载 javascript制作照片墙及制作过程中出现的问题
 博客 DSP28335—FLASH烧写的方法
 下载 CesiumLabApkServemaster.zip
 学院 【数据分析】 量化交易策略模型
 学院 JavaWeb化妆品购物商城毕业设计 大学生毕业设计教学视频
 下载 模拟技术中的简介一种数控机床的网络控制系统
 学院 Spring AOP从认识到源码
 学院 手把手教你手写Spring框架(附源码)
 博客 SAP 资产相关日期
 博客 Android关于相机使用的一点思考
 博客 嵌入式算法范围滤波法
 博客 数组的扩容
 下载 PHP获取网页所有连接的方法(附demo源码下载)
 博客 原生手写顶部底部导航
 博客 vue的SPA项目，点击按钮实现全屏
 下载 基于DSP控制的25Hz逆变电源抗负荷冲击策略
 学院 Unity基础入门
 下载 模拟技术中的解析一种新型PID控制的全数字锁相环
 博客 C#处理html标签一些正则表达式整理收集