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. css实现背景图片模糊

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  2. HDU 5907 Find Q dp

    Find Q 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5907 Description Byteasar is addicted to the ...

  3. 重温JavaScript预编译的四个步骤

    JS是解释型语言,运行过程分三步: 一.语法分析(检查代码是否存在语法错误): 二.预编译(代码执行之前,在内存中开辟空间,存放变量与函数): 三.解释执行(执行JS代码): 理解预编译的过程,对于理 ...

  4. [原创]WebScarab工具介绍

    [原创]WebScarab工具介绍 一 WebScarab介绍 WebScarab是一个用来分析使用HTTP和HTTPS协议的应用程序框架.其原理很简单,WebScarab可以记录它检测到的会话内容( ...

  5. ubuntu下smokeping安装配置

    0.参考文件 http://wenku.baidu.com/view/950fbb0a79563c1ec5da71b1 http://aaaxiang000.blog.163.com/blog/sta ...

  6. GoDaddy Linux主机支持机房的更换

    GoDaddy Linux主机支持机房的更换 http://godaddy.idcspy.com/godaddy-change-data-center GoDaddy推出中文界面后,小编发现虚拟主机有 ...

  7. ibatis.net:第四天,Update 和 Delete

    xml <update id="UpdateOrder" parameterClass="Order"> UPDATE [Orders] SET C ...

  8. (转载):ASCII,Unicode和UTF-8 编码

    UTF-8是Unicode的一种实现方式,也就是它的字节结构有特殊要求,所以我们说一个汉字的范围是0X4E00到0x9FA5,是指unicode值,至于放在utf-8的编码里去就是由三个字节来组织,所 ...

  9. maven打包时跳过单元测试

    运行mvn install时跳过Test <project> [...] <build> <plugins> <plugin> <groupId& ...

  10. 将win7电脑无线网变身WiFi热点,让手机、笔记本共享上网

    1.以管理员身份运行命令提示符:快捷键win+R→输入cmd→回车 2.启用并设定虚拟WiFi网卡:运行命令:netsh wlan set hostednetwork mode=allow ssid= ...