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. asp.net权限控制配置web.config

    项目下 有三个文件夹 A,B,C 验正方式是 Forms 验正 我要设置他们的访问权限为, A,匿名可访问 B,普通用户授权后才能访问 C,只允许管理员访问 <configuration> ...

  2. POJ 3294 后缀数组

    题目链接:http://poj.org/problem?id=3294 题意:给定n个字符串,求一个最长子串要求在超过一半的字符串中出现过. 如果多解按字典序输出 思路:根据<<后缀数组— ...

  3. SU unisam命令学习

  4. redis 的使用 (sort set排序集合类型操作)

    sort set排序集合类型 释义: sort set 是 string 类型的集合 sort set 的每个元素 都会关联一个 权 通过 权值 可以有序的获取集合中的元素 应用场合: 获取热门帖子( ...

  5. http://www.cnblogs.com/summers/p/3225375.html

    http://www.cnblogs.com/summers/p/3225375.html

  6. 用super daemon xinetd进行安全配置

    xinetd 可以进行安全性或者是其他的管理机制的控制,这些控制手段都可以让我们的服务更为安全,资源管理更为合理.一些对客户端开放较多权限的服务(例如telnet)或者本身不带有管理机制的服务就可以通 ...

  7. UVa 10870 & 矩阵快速幂

    题意: 求一个递推式(不好怎么概括..)的函数的值. 即 f(n)=a1f(n-1)+a2f(n-2)+...+adf(n-d); SOL: 根据矩阵乘法的定义我们可以很容易地构造出矩阵,每次乘法即可 ...

  8. UVA 11754 (暴力+中国剩余定理)

    题目链接: http://www.bnuoj.com/v3/problem_show.php?pid=20172 题目大意:有C个模方程,每个方程可能有k余数,求最小的S个解. 解题思路: 看见模方程 ...

  9. Android NumberPicker 修改分割线颜色和高度及字体颜色大小

    (1)重写NumberPicker已达到修改显示字体颜色大小 public class TextColorNumberPicker extends NumberPicker { public Text ...

  10. Leetcode Unique Binary Search Trees

    Given n, how many structurally unique BST's (binary search trees) that store values 1...n? For examp ...