zoukankan      html  css  js  c++  java
  • usaco-4.1-fence6-passed

    呵呵,这也能过?

    /*
    ID: qq104801
    LANG: C++
    TASK: fence6
    */
    
    #include <iostream>
    #include <fstream>
    #include <cstring>
    #include <vector>
    #include <queue>
    #include <stack>
    #include <algorithm>
    using namespace std;
    
    const int INF=1<<25;
    const int nmax=200;
    static int n,a[nmax][nmax],d[nmax][nmax];
    static int len[nmax],le[nmax][nmax],rig[nmax][nmax];
    static int s,ans;
    
    void test()
    {    
        freopen("fence6.in","r",stdin);
        freopen("fence6.out","w",stdout);  
        //init readin and change
        cin>>n;
        for(int i=1;i<=n;i++)
            for(int j=1;j<=n;j++)a[i][j]=INF;
        
        for(int i=1;i<=n;i++)
        {
            cin>>s;
            cin>>len[s]>>le[s][0]>>rig[s][0];
            for(int j=1;j<=le[s][0];j++)cin>>le[s][j];
            for(int j=1;j<=rig[s][0];j++)cin>>rig[s][j];
        }
        
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=le[i][0];j++)a[i][le[i][j]]=len[i]+len[le[i][j]];
            for(int j=1;j<=rig[i][0];j++)a[i][rig[i][j]]=len[i]+len[rig[i][j]];
        }
    
        for(int i=1;i<=n;i++)
            for(int j=1;j<=n;j++)d[i][j]=a[i][j];
        //work Floyd
        ans=1<<30;
        for(int k=1;k<=n;k++)
        {
            for(int i=1;i<=le[k][0];i++)
            {
                int ii=le[k][i];
                if(ii<k)
                {
                    for(int j=1;j<=rig[k][0];j++)
                    {
                        int jj=rig[k][j];
                        if(jj<k)
                            ans=min(ans,a[ii][jj]+d[k][ii]+d[k][jj]);
                    }
                }
            }
            for(int i=1;i<=n;i++)
                for(int j=1;j<=n;j++)
                    a[i][j]=min(a[i][j],a[i][k]+a[k][j]);
        }
        cout<<ans/2<<endl;
    }
    
    int main () 
    {        
        test();        
        return 0;
    }

    test data:

    USACO Training
    Grader Results     
    13 users online
    BGD/1 CHN/4 USA/8
    
    USER: cn tom [qq104801]
    TASK: fence6
    LANG: C++
    
    Compiling...
    Compile: OK
    
    Executing...
       Test 1: TEST OK [0.008 secs, 4000 KB]
       Test 2: TEST OK [0.008 secs, 4000 KB]
       Test 3: TEST OK [0.005 secs, 4000 KB]
       Test 4: TEST OK [0.005 secs, 4000 KB]
       Test 5: TEST OK [0.005 secs, 4000 KB]
       Test 6: TEST OK [0.011 secs, 4000 KB]
       Test 7: TEST OK [0.005 secs, 4000 KB]
       Test 8: TEST OK [0.005 secs, 4000 KB]
       Test 9: TEST OK [0.022 secs, 4000 KB]
    
    All tests OK.
    
    YOUR PROGRAM ('fence6') WORKED FIRST TIME! That's fantastic -- and a rare thing. Please accept these special automated congratulations.
    
    Here are the test data inputs:
    
    ------- test 1 ----
    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
    ------- test 2 ----
    3
    1 1 1 1
    2
    3
    2 1 1 1
    3
    1
    3 1 1 1
    1
    2
    ------- test 3 ----
    6
    1 3 2 2
    2 3
    6 5
    3 3 2 2
    1 2
    4 5
    5 5 2 2
    3 4
    6 1
    2 3 2 2
    6 4
    1 3
    4 5 2 2
    3 5
    2 6
    6 5 2 2
    1 5
    4 2
    ------- test 4 ----
    12
    1 100 1 2
    2
    3 4
    2 99 1 1
    3
    1
    3 101 1 2
    2
    1 4
    4 3 2 2
    5 7
    1 3
    5 76 2 1
    7 4
    6
    6 75 1 2
    5
    8 9
    7 77 2 1
    5 4
    8
    8 74 1 2
    7
    6 9
    9 4 2 2
    10 12
    6 8
    10 102 2 1
    12 9
    11
    11 100 1 1
    10
    12
    12 101 1 2
    11
    9 10
    ------- test 5 ----
    12
    1 24 1 7
    2
    10 9 12 3 4 6 7
    2 37 1 1
    1
    3
    3 214 1 7
    2
    1 10 9 12 4 6 7
    4 83 1 7
    5
    1 10 9 3 12 6 7
    5 247 1 1
    4
    6
    6 10 1 7
    5
    1 10 3 12 4 7 9
    7 15 1 7
    8
    1 10 3 12 4 6 9
    8 73 1 1
    7
    9
    9 135 1 7
    8
    1 10 3 12 4 6 7
    10 42 1 7
    11
    1 3 12 4 6 7 9
    11 191 1 1
    10
    12
    12 85 1 7
    11
    10 1 3 4 6 7 9
    ------- test 6 ----
    14
    1 1 1 1
    14
    2
    4 1 1 1
    5
    3
    13 1 1 1
    14
    12
    14 1 1 1
    13
    1
    9 2 1 2
    6
    10 8
    7 14 2 1
    5 6
    8
    11 1 1 1
    12
    10
    2 1 1 1
    1
    3
    10 1 1 2
    11
    9 8
    8 23 2 1
    10 9
    7
    3 1 1 1
    2
    4
    6 2 2 1
    5 7
    9
    5 1 1 2
    4
    6 7
    12 1 1 1
    13
    11
    ------- test 7 ----
    31
    16 10 2 2
    2 15
    17 18
    1 80 1 1
    2
    3
    2 80 1 2
    1
    15 16
    4 80 2 2
    3 5
    8 9
    5 200 2 1
    3 4
    7
    21 80 1 2
    18
    20 22
    22 80 2 2
    20 21
    23 27
    6 160 2 2
    9 10
    7 14
    7 80 1 2
    5
    6 14
    8 10 2 1
    4 9
    15
    17 10 2 1
    16 18
    19
    9 10 2 2
    4 8
    6 10
    10 10 2 1
    9 6
    11
    11 10 1 2
    10
    29 12
    14 80 2 1
    6 7
    13
    15 10 2 1
    2 16
    8
    18 80 2 1
    16 17
    21
    30 10 2 2
    19 20
    24 23
    19 10 1 2
    17
    20 30
    20 80 2 2
    19 30
    21 22
    23 80 2 2
    22 27
    30 24
    12 80 2 2
    11 29
    13 26
    13 80 1 2
    14
    12 26
    24 10 2 1
    23 30
    31
    25 80 2 2
    27 28
    31 29
    26 80 2 1
    12 13
    28
    27 80 2 2
    22 23
    25 28
    28 80 2 1
    27 25
    26
    3 80 1 2
    1
    4 5
    29 10 2 2
    11 12
    31 25
    31 10 1 2
    24
    29 25
    ------- test 8 ----
    100
    1 8 1 1
    100
    2
    2 8 1 1
    1
    3
    3 8 1 1
    2
    4
    4 8 1 1
    3
    5
    5 8 1 1
    4
    6
    6 8 1 1
    5
    7
    7 8 1 1
    6
    8
    8 8 1 1
    7
    9
    9 8 1 1
    8
    10
    10 8 1 1
    9
    11
    11 8 1 1
    10
    12
    12 8 1 1
    11
    13
    13 8 1 1
    12
    14
    14 8 1 1
    13
    15
    15 8 1 1
    14
    16
    16 8 1 1
    15
    17
    17 8 1 1
    16
    18
    18 8 1 1
    17
    19
    19 8 1 1
    18
    20
    20 8 1 1
    19
    21
    21 8 1 1
    20
    22
    22 8 1 1
    21
    23
    23 8 1 1
    22
    24
    24 8 1 1
    23
    25
    25 8 1 1
    24
    26
    26 8 1 1
    25
    27
    27 8 1 1
    26
    28
    28 8 1 1
    27
    29
    29 8 1 1
    28
    30
    30 8 1 1
    29
    31
    31 8 1 1
    30
    32
    32 8 1 1
    31
    33
    33 8 1 1
    32
    34
    34 8 1 1
    33
    35
    35 8 1 1
    34
    36
    36 8 1 1
    35
    37
    37 8 1 1
    36
    38
    38 8 1 1
    37
    39
    39 8 1 1
    38
    40
    40 8 1 1
    39
    41
    41 8 1 1
    40
    42
    42 8 1 1
    41
    43
    43 8 1 1
    42
    44
    44 8 1 1
    43
    45
    45 8 1 1
    44
    46
    46 8 1 1
    45
    47
    47 8 1 1
    46
    48
    48 8 1 1
    47
    49
    49 8 1 1
    48
    50
    50 8 1 1
    49
    51
    51 8 1 1
    50
    52
    52 8 1 1
    51
    53
    53 8 1 1
    52
    54
    54 8 1 1
    53
    55
    55 8 1 1
    54
    56
    56 8 1 1
    55
    57
    57 8 1 1
    56
    58
    58 8 1 1
    57
    59
    59 8 1 1
    58
    60
    60 8 1 1
    59
    61
    61 8 1 1
    60
    62
    62 8 1 1
    61
    63
    63 8 1 1
    62
    64
    64 8 1 1
    63
    65
    65 8 1 1
    64
    66
    66 8 1 1
    65
    67
    67 8 1 1
    66
    68
    68 8 1 1
    67
    69
    69 8 1 1
    68
    70
    70 8 1 1
    69
    71
    71 8 1 1
    70
    72
    72 8 1 1
    71
    73
    73 8 1 1
    72
    74
    74 8 1 1
    73
    75
    75 8 1 1
    74
    76
    76 8 1 1
    75
    77
    77 8 1 1
    76
    78
    78 8 1 1
    77
    79
    79 8 1 1
    78
    80
    80 8 1 1
    79
    81
    81 8 1 1
    80
    82
    82 8 1 1
    81
    83
    83 8 1 1
    82
    84
    84 8 1 1
    83
    85
    85 8 1 1
    84
    86
    86 8 1 1
    85
    87
    87 8 1 1
    86
    88
    88 8 1 1
    87
    89
    89 8 1 1
    88
    90
    90 8 1 1
    89
    91
    91 8 1 1
    90
    92
    92 8 1 1
    91
    93
    93 8 1 1
    92
    94
    94 8 1 1
    93
    95
    95 8 1 1
    94
    96
    96 8 1 1
    95
    97
    97 8 1 1
    96
    98
    98 8 1 1
    97
    99
    99 8 1 1
    98
    100
    100 8 1 1
    99
    1
    ------- test 9 ----
    93
    1 25 2 1
    90 93
    2
    2 25 1 1
    1
    3
    3 25 1 1
    2
    4
    4 25 1 1
    3
    5
    5 25 1 1
    4
    6
    6 25 1 1
    5
    7
    7 25 1 1
    6
    8
    8 25 1 1
    7
    9
    9 25 1 1
    8
    10
    10 25 1 1
    9
    11
    11 25 1 1
    10
    12
    12 25 1 1
    11
    13
    13 25 1 1
    12
    14
    14 25 1 1
    13
    15
    15 25 1 1
    14
    16
    16 25 1 1
    15
    17
    17 25 1 1
    16
    18
    18 25 1 1
    17
    19
    19 25 1 1
    18
    20
    20 25 1 1
    19
    21
    21 25 1 1
    20
    22
    22 25 1 1
    21
    23
    23 25 1 1
    22
    24
    24 25 1 1
    23
    25
    25 25 1 1
    24
    26
    26 25 1 1
    25
    27
    27 25 1 1
    26
    28
    28 25 1 1
    27
    29
    29 25 1 1
    28
    30
    30 25 1 2
    29
    31 91
    31 25 2 1
    30 91
    32
    32 25 1 1
    31
    33
    33 25 1 1
    32
    34
    34 25 1 1
    33
    35
    35 25 1 1
    34
    36
    36 25 1 1
    35
    37
    37 25 1 1
    36
    38
    38 25 1 1
    37
    39
    39 25 1 1
    38
    40
    40 25 1 1
    39
    41
    41 25 1 1
    40
    42
    42 25 1 1
    41
    43
    43 25 1 1
    42
    44
    44 25 1 1
    43
    45
    45 25 1 1
    44
    46
    46 25 1 1
    45
    47
    47 25 1 1
    46
    48
    48 25 1 1
    47
    49
    49 25 1 1
    48
    50
    50 25 1 1
    49
    51
    51 25 1 1
    50
    52
    52 25 1 1
    51
    53
    53 25 1 1
    52
    54
    54 25 1 1
    53
    55
    55 25 1 1
    54
    56
    56 25 1 1
    55
    57
    57 25 1 1
    56
    58
    58 25 1 1
    57
    59
    59 25 1 1
    58
    60
    60 25 1 2
    59
    61 92
    61 25 2 1
    60 92
    62
    62 25 1 1
    61
    63
    63 25 1 1
    62
    64
    64 25 1 1
    63
    65
    65 25 1 1
    64
    66
    66 25 1 1
    65
    67
    67 25 1 1
    66
    68
    68 25 1 1
    67
    69
    69 25 1 1
    68
    70
    70 25 1 1
    69
    71
    71 25 1 1
    70
    72
    72 25 1 1
    71
    73
    73 25 1 1
    72
    74
    74 25 1 1
    73
    75
    75 25 1 1
    74
    76
    76 25 1 1
    75
    77
    77 25 1 1
    76
    78
    78 25 1 1
    77
    79
    79 25 1 1
    78
    80
    80 25 1 1
    79
    81
    81 25 1 1
    80
    82
    82 25 1 1
    81
    83
    83 25 1 1
    82
    84
    84 25 1 1
    83
    85
    85 25 1 1
    84
    86
    86 25 1 1
    85
    87
    87 25 1 1
    86
    88
    88 25 1 1
    87
    89
    89 25 1 1
    88
    90
    90 25 1 2
    89
    1 93
    93 250 2 2
    1 90
    92 91
    91 250 2 2
    92 93
    30 31
    92 250 2 2
    91 93
    61 60
    
    Keep up the good work!
    Thanks for your submission!
    View Code
    /***********************************************

    看书看原版,原汁原味。

    不会英文?没关系,硬着头皮看下去慢慢熟练,才会有真正收获。

    没有原书,也要网上找PDF来看。

    网上的原版资料多了去了,下载东西也到原始下载点去看看。

    你会知其所以然,呵呵。

    ***********************************************/

  • 相关阅读:
    jQuery on注册事件
    前端表格(Table)多条数据可以增加行删除行json封装后Post数据到后台处理
    导出Excel数据
    C#在一个实体类上新加字段并把另外一个实体类的字段值赋给它
    函数(五)-内置函数
    函数(四)-命名空间与作用域
    函数(三)-return与函数的调用
    函数(二)- 参数
    函数(一)-基本格式
    字符串格式化
  • 原文地址:https://www.cnblogs.com/dpblue/p/3976602.html
Copyright © 2011-2022 走看看