Pro.ID22546 TitlePlugged In Title链接http://10.20.2.8/oj/exercise/problem?problem_id=22546 AC0 Submit0 Ratio- 时间&空间限制描述The designers of the new NentindoBoxStation game system want to provide interactive input from many different sources. Using a special sensor-lined "electronic cocoon" users should be able to do things such as control simulated laser cannons by moving their eyebrows, accelerate/decelerate by wiggling their ears, steer in three-dimensional space by rotating their ankles ... the possibilities are endless.
Clearly pin 1 can be connected only to holes 1’, 4’, 13’, or 16’ (depending on how the plug is rotated with respect to the socket). Pin 2 can be connected only to holes 2’, 3’, 5’, 8’, 9’, 12’, 14’, or 15’ (if we consider all rotations and connections in both the back and front of the plug). For instance, if we are given the set (1,3’ ), (5,7’ ), (2,6’ ) for the plug and socket above, the average distance for this set of pairs is 2.6667 if we put the plug into the front of the socket without rotating the socket, but is only 2.3333 if we rotate the socket 180 degrees and then flip it horizontally, placing the plug in the back of the socket. 输入Input will consist of a set of scenarios. Each scenario consists of a positive integer n, the side length of the plug and socket (less than or equal to 100) on a line by itself, followed by a positive integer m (less than or equal to n2 ) on a line by itself, followed by m lines, each containing a pair of positive integers in the range 1, . . . , n2. You may assume that no two pairs will have either a common first element or a common second element. The first integer represents a pin position in the plug, the second is a hole position in the socket. The final scenario is followed by 0 on a line by itself. 输出Description The designers of the new NentindoBoxStation game system want to provide interactive input from many different sources. Using a special sensor-lined "electronic cocoon" users should be able to do things such as control simulated laser cannons by moving their eyebrows, accelerate/decelerate by wiggling their ears, steer in three-dimensional space by rotating their ankles ... the possibilities are endless.
Clearly pin 1 can be connected only to holes 1’, 4’, 13’, or 16’ (depending on how the plug is rotated with respect to the socket). Pin 2 can be connected only to holes 2’, 3’, 5’, 8’, 9’, 12’, 14’, or 15’ (if we consider all rotations and connections in both the back and front of the plug). For instance, if we are given the set (1,3’ ), (5,7’ ), (2,6’ ) for the plug and socket above, the average distance for this set of pairs is 2.6667 if we put the plug into the front of the socket without rotating the socket, but is only 2.3333 if we rotate the socket 180 degrees and then flip it horizontally, placing the plug in the back of the socket. Input Input will consist of a set of scenarios. Each scenario consists of a positive integer n, the side length of the plug and socket (less than or equal to 100) on a line by itself, followed by a positive integer m (less than or equal to n2 ) on a line by itself, followed by m lines, each containing a pair of positive integers in the range 1, . . . , n2. You may assume that no two pairs will have either a common first element or a common second element. The first integer represents a pin position in the plug, the second is a hole position in the socket. The final scenario is followed by 0 on a line by itself. Output For each scenario, output the scenario number (starting with 1), followed by the smallest average distance achievable between the m pin/socket pairs after rotations and reflections are considered (assuming an appropriate routing box is used), in a line of the form: Scenerio n: smallest average = avg where avg is the average is rounded, and displayed, to four decimal places. Separate lines of output by a single blank line. Sample Input 4 3 1 3 5 7 2 6 23 1 4 2 2 4 1 0 Sample Output Scenario 1: smallest average = 2.3333 Scenario 2: smallest average = 1.0000 Source 样例输入4 3 1 3 5 7 2 6 23 1 4 2 2 4 1 0 样例输出Scenario 1: smallest average = 2.3333 Scenario 2: smallest average = 1.0000 作者 |