10178_FenceLoops

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

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

Pro.ID

10178

Title

Fence Loops

Title链接

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

AC

3

Submit

12

Ratio

25.00%

时间&空间限制

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

    The fences that surround Farmer Brown's collection of pastures have gotten out of control. They are made up of straight segments from 1 through 200 feet long that join together only at their endpoints though sometimes more than two fences join together at a given endpoint. The result is a web of fences enclosing his pastures. Farmer Brown wants to start to straighten things out. In particular, he wants to know which of the pastures has the smallest perimeter.

    Farmer Brown has numbered his fence segments from 1 to N (N = the total number of segments). He knows the following about each fence segment:

    • the length of the segment

    • the segments which connect to it at one end

    • the segments which connect to it at the other end.

    Happily, no fence connects to itself.

    Given a list of fence segments that represents a set of surrounded pastures, write a program to compute the smallest perimeter of any pasture. As an example, consider a pasture arrangement, with fences numbered 1 to 10 that looks like this one (the numbers are fence ID numbers):

    1
     +---------------+
     |\             /|
    2| \7          / |
     |  \         /  |
      +---+       /   |6
     | 8  \     /10  |
    3|     \9  /     |
     |      \ /      |
     +-------+-------+
      4       5

    The pasture with the smallest perimeter is the one that is enclosed by fence segments 2, 7, and 8.

    输入

    Multiple test cases. For each case:

    Line 1:  N (1 ≤ N ≤ 100)

    Line 2..3×N+1:  N sets of three line records:

    • The first line of each record contains four integers: s, the segment number (1 ≤ sN); Ls , the length of the segment (1 ≤ Ls ≤ 255); N1s (1 ≤ N1s ≤ 8) the number of items on the subsequent line; and N2s the number of items on the line after that (1 ≤ N2s ≤ 8).

    • The second line of the record contains N1 integers, each representing a connected line segment on one end of the fence.

    • The third line of the record contains N2 integers, each representing a connected line segment on the other end of the fence.

    输出

    Description

    The fences that surround Farmer Brown's collection of pastures have gotten out of control. They are made up of straight segments from 1 through 200 feet long that join together only at their endpoints though sometimes more than two fences join together at a given endpoint. The result is a web of fences enclosing his pastures. Farmer Brown wants to start to straighten things out. In particular, he wants to know which of the pastures has the smallest perimeter.

    Farmer Brown has numbered his fence segments from 1 to N (N = the total number of segments). He knows the following about each fence segment:

    • the length of the segment

    • the segments which connect to it at one end

    • the segments which connect to it at the other end.

    Happily, no fence connects to itself.

    Given a list of fence segments that represents a set of surrounded pastures, write a program to compute the smallest perimeter of any pasture. As an example, consider a pasture arrangement, with fences numbered 1 to 10 that looks like this one (the numbers are fence ID numbers):

    1
     +---------------+
     |\             /|
    2| \7          / |
     |  \         /  |
      +---+       /   |6
     | 8  \     /10  |
    3|     \9  /     |
     |      \ /      |
     +-------+-------+
      4       5

    The pasture with the smallest perimeter is the one that is enclosed by fence segments 2, 7, and 8.

    Input

    Multiple test cases. For each case:

    Line 1:  N (1 ≤ N ≤ 100)

    Line 2..3×N+1:  N sets of three line records:

    • The first line of each record contains four integers: s, the segment number (1 ≤ sN); Ls , the length of the segment (1 ≤ Ls ≤ 255); N1s (1 ≤ N1s ≤ 8) the number of items on the subsequent line; and N2s the number of items on the line after that (1 ≤ N2s ≤ 8).

    • The second line of the record contains N1 integers, each representing a connected line segment on one end of the fence.

    • The third line of the record contains N2 integers, each representing a connected line segment on the other end of the fence.

    Output

    For each case, output a single line with a single integer that represents the shortest surrounded perimeter.

    Sample Input

    10
    1 16 2 2
    2 7
    10 6
    2 3 2 2
    1 7
    8 3
    3 3 2 1
    8 2
    4
    4 8 1 3
    3
    9 10 5
    5 8 3 1
    9 10 4
    6
    6 6 1 2
    5
    1 10
    7 5 2 2
    1 2
    8 9
    8 4 2 2
    2 3
    7 9
    9 5 2 3
    7 8
    4 5 10
    10 10 2 3
    1 6
    4 9 5

    Sample Output

    12

    Source

    样例输入

    10
    1 16 2 2
    2 7
    10 6
    2 3 2 2
    1 7
    8 3
    3 3 2 1
    8 2
    4
    4 8 1 3
    3
    9 10 5
    5 8 3 1
    9 10 4
    6
    6 6 1 2
    5
    1 10
    7 5 2 2
    1 2
    8 9
    8 4 2 2
    2 3
    7 9
    9 5 2 3
    7 8
    4 5 10
    10 10 2 3
    1 6
    4 9 5

    样例输出

    12

    作者


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部