1005 输出用%f,1009别做了

Problem E

Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 96   Accepted Submission(s) : 51
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[sub]Mi[/sub] and L[sub]Mi[/sub], which means that the distance between the i-th town and the S[sub]Mi[/sub] town is L[sub]Mi[/sub].
 
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
 
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#define INF 0x3f3f3f3f
using namespace std;
int map[][],dis[];
bool used[];
int sea[];
int n,k,minx;
void init()
{
for(int i=;i<n;i++)
{
for(int j=;j<n;j++)
{
if(i==j) map[i][j] = ;
map[i][j] = INF;
}
}
}
void dijkstral(int s)
{
memset(used,false,sizeof(used));
for(int i=;i<n;i++)
{
dis[i] = map[][i];
} dis[s] = ;
while()
{
int v = -;
for(int u=;u<n;u++)
{
if(!used[u]&&(v==-||dis[u]<dis[v])) v = u;
}
if(v==-) break;
used[v] = true;
for(int u=;u<n;u++)
{
dis[u] = min(dis[u],dis[v]+map[v][u]);
}
}
int minm = INF; for (int i=;i<k;i++)
{
minm = min(minm,dis[sea[i]]);
}
printf ("%d\n",minm);
}
int main()
{
int s,l;
int M,P;
int N;
while(~scanf("%d",&N))
{
int cnt = ;
int y = ;
n = N;
init();
while(N--)
{ scanf("%d%d",&M,&P);
if(P)
{
sea[y++] = cnt;
}
for(int i=;i<M;i++)
{
scanf("%d%d",&s,&l);
map[cnt][s] = min(l,map[cnt][s]);
map[s][cnt] = min(l,map[cnt][s]);
}
cnt++;
}
dijkstral();
}
return ;
}

随机推荐

  1. 从两个平方算法到分治算法-java

    先来看看问题的来源,假设有这么一个数组: 1 2 -5 4 -2 3 -3 4 -15 我们要求出其中连续字数组的和的最大值 例如这么可以很明显看出 4+ –2 + 3 + –3 + 4 = 6 所有 ...

  2. CentOS VMware 配置IP小结 静态 配置 桥接 NAT

    系统启动后可先ping下外网或局域网内其它机器. 如果配置虚拟机时选择的NAT上网方式,后面需要配置固定IP,请先参见VMware NAT方式下设置静态IP获得可用的IP范围和网关等信息. 先将ifc ...

  3. DOM--3 DOM核心和DOM2 HTML(2)

    核心Node对象 由于继承扩展的关系,DOM中大部分对象会有Node对象的属性和方法,其中包括: nodeName DOM2核心中规定的每种nodeType预期的nodeName值 对象 返回值 El ...

  4. 17996 Daily Cool Run (dp)

    时间限制:1000MS  内存限制:65535K 提交次数:0 通过次数:0 题型: 编程题   语言: 不限定 Description Daily Cool Run is a popular gam ...

  5. jQuery跨域

    其实jQuery跨域很简单很简单,你记住格式就好,跨域的原理请参考 <jsonp跨域> jQuery跨域代码: $.ajax({ url:'https://suggest.taobao.c ...

  6. JavaScript 的同源策略

    同源策略限制了一个源(origin)中加载文本或脚本与来自其它源(origin)中资源的交互方式. 同源定义 如果两个页面拥有相同的协议(protocol),端口(如果指定),和主机,那么这两个页面就 ...

  7. js中for in 和 for each in的用法和区别

    区别一:           for in是javascript 1.0 中发布的.         for each in是作为E4X标准的一部分在javascript 1.6中发布的,而它不是EC ...

  8. django 自定义表单

    创建一个1.html的东西 <html> <body> <form method='post'> {{form.as_p}} <input type=&quo ...

  9. BZOJ3562 : [SHOI2014]神奇化合物

    可以发现,从头到尾有一堆点是始终连在一起的,所以把没被删掉的一开始就有的边都加上后求出每个联通块, 缩完点后我们发现,边数也减少得差不多了,剩下的就直接暴力. #include<cstdio&g ...

  10. css flexbox水平垂直

    display: -webkit-box;display: -webkit-flex;display: -moz-box;display: -moz-flex;display: -ms-flexbox ...