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

     
  • 相关阅读:
    3524: [Poi2014]Couriers -- 主席树
    bzoj 2190: [SDOI2008]仪仗队 -- 欧拉函数
    模板 -- 树链剖分
    bzoj 1823: [JSOI2010]满汉全席 -- 2-sat
    bzoj 1704: [Usaco2007 Mar]Face The Right Way 自动转身机 -- 贪心
    bzoj 1231: [Usaco2008 Nov]mixup2 混乱的奶牛 -- 状压DP
    redis 主从复制
    redis 事务
    redis持久化——AOF
    redis 持久化 ——RDB
  • 原文地址:https://www.cnblogs.com/kuangbin/p/2119685.html
Copyright © 2011-2022 走看看