Seaside

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

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 S
Mi and L
Mi, which means that the distance between the i-th town and the S
Mi town is L
Mi.
 
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
 


题目意思很好懂,当时我们竟然想到了一步步dp,范围很小,n最大才为10而已,可以直接用floyd,只是一直不敢交,觉得存在bug,因为n为0的时候不知道怎么处理。。最后突然交了一发,A了,应该没有n=0的数据。。

题目地址:Seaside

AC代码:
#include<iostream>
#include<cstring>
#include<cstdio>
#define maxn 1e12
using namespace std;
long long dis[15][15];
int issea[15],n; void floyd()
{
int i,j,k;
for(k=0;k<n;k++)
for(i=0;i<n;i++)
for(j=0;j<n;j++)
if(dis[i][j]>dis[i][k]+dis[k][j])
dis[i][j]=dis[i][k]+dis[k][j];
} int main()
{
int i,j;
long long ans;
while(cin>>n)
{
ans=maxn;
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
dis[i][j]=maxn;
dis[i][i]=0;
} memset(issea,0,sizeof(issea)); //是否是海边
for(i=0;i<n;i++)
{
int a,b,c,d;
scanf("%d%d",&a,&b);
issea[i]=b;
for(j=0;j<a;j++)
{
scanf("%d%d",&c,&d);
dis[i][c]=d;
}
}
floyd();
for(i=0;i<n;i++)
if(issea[i]&&dis[0][i]<ans)
ans=dis[0][i];
cout<<ans<<endl;
}
return 0;
}

hdu 3665Seaside(简单floyd)的更多相关文章

  1. HDU 1564 简单博弈 水

    n*n棋盘,初始左上角有一个石头,每次放只能在相邻的四个位置之一,不能操作者输. 如果以初始石头编号为1作为后手,那么对于每次先手胜的情况其最后一步的四周的编号必定是奇数,且此时编号为偶数,而对于一个 ...

  2. HDU 4034 Graph(floyd,最短路,简单)

    题目 一道简单的倒着的floyd. 具体可看代码,代码可简化,你有兴趣可以简化一下,就是把那个Dijsktra所实现的功能放到倒着的floyd里面去. #include<stdio.h> ...

  3. hdu 4606 简单计算几何+floyd+最小路径覆盖

    思路:将所有的直线的两个端点和城市混在一起,将能直接到达的两个点连线,求一次floyd最短路径.二分枚举bag容量,然后按给的要先后占领的城市由前向后,把能到一步到达的建一条边.然后求一次最小路径覆盖 ...

  4. hdu 2037简单贪心--活动安排问题

    活动安排问题就是要在所给的活动集合中选出最大的相容活动子集合,是可以用贪心算法有效求解的很好例子.该问题要求高效地安排一系列争用某一公共资源的活动.贪心算法提供了一个简单.漂亮的方法使得尽可能多的活动 ...

  5. HDU 2089 简单数位dp

    1.HDU 2089  不要62    简单数位dp 2.总结:看了题解才敲出来的,还是好弱.. #include<iostream> #include<cstring> #i ...

  6. HDU 1087 简单dp,求递增子序列使和最大

    Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 ...

  7. hdu 1596(Floyd 变形)

    http://acm.hdu.edu.cn/showproblem.php?pid=1596 find the safest road Time Limit: 10000/5000 MS (Java/ ...

  8. hdu 1217 (Floyd变形)

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=1217 Arbitrage Time Limit: 2000/1000 MS (Java/Others)   ...

  9. hdu 1869 (Floyd)

    http://acm.hdu.edu.cn/showproblem.php?pid=1869 六度分离 Time Limit: 5000/1000 MS (Java/Others)    Memory ...

随机推荐

  1. Android之Android WebView常见问题及解决方案汇总

    如有转载,请声明出处: 时之沙: http://blog.csdn.net/t12x3456 Android WebView常见问题解决方案汇总: 就目前而言,如何应对版本的频繁更新呢,又如何灵活多变 ...

  2. LPC-LINK 2

    LPC-Link 2 is an extensible, stand-alone debug adapter that can be configured to support various dev ...

  3. bitnami-redmine邮件告警配置

    配置 bitnami-redmine的配置文件与单纯的redmine配置文件可能并不相同,在这里我们需要打开一下配置文件: /opt/bitnami/apps/redmine/htdocs/confi ...

  4. vuex 基础:教程和说明

    作者注:[2016.11 更新]这篇文章是基于一个非常旧的 vuex api 版本而写的,代码来自于2015年12月.但是,它仍能针对下面几个问题深入探讨: vuex 为什么重要 vuex 如何工作 ...

  5. DbContextScope,A simple and flexible way to manage your Entity Framework DbContext instances,by mehdime

    DbContextScope A simple and flexible way to manage your Entity Framework DbContext instances. DbCont ...

  6. zTree树

    <link rel="stylesheet" href="/static/zTreeV3/css/metroStyle/metroStyle.css" t ...

  7. Map HashMap 排序 迭代循环 修改值

    HashMap dgzhMap = Dict.getDict("dgzh"); Iterator it_d = dgzhMap.entrySet().iterator(); whi ...

  8. javascript游戏引擎

    基于JavaScript开发的游戏是唯一一个能够跨桌面,Web和移动三种平台的.今天,本文向大家推荐一些非常棒的JavaScript游戏开发框架. AD:干货来了,不要等!WOT2015 北京站演讲P ...

  9. 超能英雄第一至四季/全集Heroes迅雷下载

    本季第一.二.三.四季 Heroes Season (2006-2009) 看点:<Heroes>是NBC电视台于2006年九月开播的最新科幻电视剧.Heroes(中文剧名为“英雄”或“天 ...

  10. Android之仿String的对象驻留

    String a = "abc"; String b = "abc"; a == b     true; 变量a和变量b是同一个值.这不只是说它俩的值是一样的, ...