10270_LazyJumpingFrog

2022-5-16 18:16| 发布者: Hocassian| 查看: 53| 评论: 0|原作者: 肇庆学院ACM合集

摘要:
C:\Users\Administrator\Downloads\2019-10-12-10-14-3-89504715315300-Problem List-采集的数据-后羿采集器.html

Pro.ID

10270

Title

Lazy Jumping Frog

Title链接

http://10.20.2.8/oj/exercise/problem?problem_id=10270

AC

0

Submit

0

Ratio

-

时间&空间限制

  • Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Others)
  • 描述

    Mr. Frog lives in a grid-like marsh of rectangular shape, composed of equally-sized cells, some of which are dry, some of which are only watery places. Mr. Frog lives in a dry cell and can jump only from a dry cell to another dry cell on his wanderings around the marsh.

    Mr. Frog wants to visit his girlfriend, Ms. Toad, who also lives in a dry cell in the same marsh. But Mr. Frog is lazy, and wants to spend the minimum amount of energy in his jumping way to Ms. Toad's home. Mr. Frog knows how much energy he spends in any of his jumps. For any single jump, Mr. Frog always uses the following figure to determine which are the possible target cells from his current position (the cell marked F), and the corresponding energy spent in the jump, in calories. Any other cell is unreachable from Mr. Frog's current position with a single jump.

    Your task is to determine the minimum amount of energy that Mr. Frog needs to spend to get from his home to Ms. Toad's home.

    输入

    The input contains several test cases. The first line of a test case contains two integers, C and R, indicating respectively the number of columns and rows of the marsh ( 1 ≤ C, R 1000 ).

    The second line of a test case contains four integers Cf , Rf , Ct, and Rt, where (Cf ,Rf ) specify Mr. Frog's home location and (Ct, Rt) specify Ms. Toad's home location ( 1 Cf , CtC  and  1 Rf ,RtR ). The third line of a test case contains an integer W ( 0 W 1000 ) indicating the number of watery places in the marsh. Each of the next W lines contains four integers C1, R1, C2, and R2 ( 1 C1C2C  and  1 R1R2R ) describing a rectangular watery place comprising cells whose coordinates (x, y) are so that C1x C2 and R1y R2. The end of input is indicated by C = R = 0.

    输出

    Description

    Mr. Frog lives in a grid-like marsh of rectangular shape, composed of equally-sized cells, some of which are dry, some of which are only watery places. Mr. Frog lives in a dry cell and can jump only from a dry cell to another dry cell on his wanderings around the marsh.

    Mr. Frog wants to visit his girlfriend, Ms. Toad, who also lives in a dry cell in the same marsh. But Mr. Frog is lazy, and wants to spend the minimum amount of energy in his jumping way to Ms. Toad's home. Mr. Frog knows how much energy he spends in any of his jumps. For any single jump, Mr. Frog always uses the following figure to determine which are the possible target cells from his current position (the cell marked F), and the corresponding energy spent in the jump, in calories. Any other cell is unreachable from Mr. Frog's current position with a single jump.

    Your task is to determine the minimum amount of energy that Mr. Frog needs to spend to get from his home to Ms. Toad's home.

    Input

    The input contains several test cases. The first line of a test case contains two integers, C and R, indicating respectively the number of columns and rows of the marsh ( 1 ≤ C, R 1000 ).

    The second line of a test case contains four integers Cf , Rf , Ct, and Rt, where (Cf ,Rf ) specify Mr. Frog's home location and (Ct, Rt) specify Ms. Toad's home location ( 1 Cf , CtC  and  1 Rf ,RtR ). The third line of a test case contains an integer W ( 0 W 1000 ) indicating the number of watery places in the marsh. Each of the next W lines contains four integers C1, R1, C2, and R2 ( 1 C1C2C  and  1 R1R2R ) describing a rectangular watery place comprising cells whose coordinates (x, y) are so that C1x C2 and R1y R2. The end of input is indicated by C = R = 0.

    Output

    For each test case in the input, your program must produce one line of output, containing the minimum calories consumed by Mr. Frog to go from his home location to Ms. Toad's home location. If there is no way Mr. Frog can get to Ms. Toad's home, your program should output impossible.

    Sample Input

    4 4
    1 1 4 2
    2
    2 1 3 3
    4 3 4 4
    4 4
    1 1 4 2
    1
    2 1 3 4
    7 6
    4 2 7 6
    5
    4 1 7 1
    5 1 5 5
    2 4 3 4
    7 5 7 5
    6 6 6 6
    0 0

    Sample Output

    14
    impossible
    12

    Source

    样例输入

    4 4
    1 1 4 2
    2
    2 1 3 3
    4 3 4 4
    4 4
    1 1 4 2
    1
    2 1 3 4
    7 6
    4 2 7 6
    5
    4 1 7 1
    5 1 5 5
    2 4 3 4
    7 5 7 5
    6 6 6 6
    0 0

    样例输出

    14
    impossible
    12

    作者


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部