zoukankan      html  css  js  c++  java
  • ACM HDU 3665Seaside

    Seaside

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 396    Accepted Submission(s): 272


    Problem Description
    XiaoY is living in a big city, there are N towns in it and some towns near the sea. All these towns are numbered from 0 to N-1 and XiaoY lives in the town numbered ’0’. There are some directed roads connecting them. It is guaranteed that you can reach any town from the town numbered ’0’, but not all towns connect to each other by roads directly, and there is no ring in this city. One day, XiaoY want to go to the seaside, he asks you to help him find out the shortest way.
     

    Input
    There are several test cases. In each cases the first line contains an integer N (0<=N<=10), indicating the number of the towns. Then followed N blocks of data, in block-i there are two integers, Mi (0<=Mi<=N-1) and Pi, then Mi lines followed. Mi means there are Mi roads beginning with the i-th town. Pi indicates whether the i-th town is near to the sea, Pi=0 means No, Pi=1 means Yes. In next Mi lines, each line contains two integers SMi and LMi, which means that the distance between the i-th town and the SMi town is LMi.
     

    Output
    Each case takes one line, print the shortest length that XiaoY reach seaside.
     

    Sample Input
    5 1 0 1 1 2 0 2 3 3 1 1 1 4 100 0 1 0 1
     

    Sample Output
    2
     

    Source
     

    Recommend
    lcy
     
     
    #include<stdio.h>
    #include
    <iostream>
    using namespace std;
    const int INF=65533;
    const int MAXN=15;
    int distances[MAXN][MAXN];
    int a[MAXN];//记录是否临近海边
    int n;
    void Floyed()
    {
    int i,j,k;
    for(k=0;k<n;k++)
    for(i=0;i<n;i++)
    for(j=0;j<n;j++)
    {
    if(distances[i][j]>distances[i][k]+distances[k][j])
    distances[i][j]
    =distances[i][k]+distances[k][j];
    }
    }
    int main()
    {
    //freopen("test.in","r",stdin);
    //freopen("test.out","w",stdout);
    int m;
    int cnt;
    int i,j;
    int b;
    int dis;
    while(scanf("%d",&n)!=EOF)
    {
    for(i=0;i<n;i++)
    for(j=0;j<n;j++)
    {
    if(i==j)distances[i][j]=0;
    else
    distances[i][j]
    =INF;
    }
    for(i=0;i<n;i++)
    {
    scanf(
    "%d%d",&m,&a[i]);
    for(j=0;j<m;j++)
    {
    scanf(
    "%d%d",&b,&dis);
    distances[i][b]
    =dis;
    }
    }
    Floyed();
    cnt
    =INF;
    for(i=0;i<n;i++)
    if(a[i])
    if(distances[0][i]<cnt)cnt=distances[0][i];
    printf(
    "%d\n",cnt);

    }
    return 0;
    }

     
  • 相关阅读:
    Django路由系统---django重点之url映射分发
    Django路由系统---Django重点之url别名
    Django路由系统---django重点之url传递一个默认参数
    Django路由系统---django重点之url命名分组
    Django路由系统---url无命名分组
    Qt中layout()->setSizeConstraint(QLayout::SetFixedSize);崩溃的问题
    关于QStandardItemModel
    qmake使用方法(自动生成Makefile文件)
    Windows下使用MakeFile(Mingw)文件
    如何在Qt Creator中创建pri文件,以及pri文件的说明
  • 原文地址:https://www.cnblogs.com/kuangbin/p/2119685.html
Copyright © 2011-2022 走看看