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;
    }

     
  • 相关阅读:
    Python--day43--mysql自增列之起始值和步长
    Python--day43--补充之主键和外键
    Python--day42--MySQL外键定义及创建
    Python--day42--mysql操作数据库及数据表和基本增删改查
    Python--day42--mysql创建用户及授权
    sql数据库基础
    Python--day41--线程池--python标准模块concurrent.futures
    C# 第三方DLL,可以实现PDF转图片,支持32位系统、64位系统
    ASP.NET 使用Session,避免用户F5刷新时重复提交(转)
    (重要,部署和发布)c# webApi 服务端和客户端 详细实例
  • 原文地址:https://www.cnblogs.com/kuangbin/p/2119685.html
Copyright © 2011-2022 走看看