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. Understanding Kafka Consumer Groups and Consumer Lag

    In this post, we will dive into the consumer side of this application ecosystem, which means looking ...

  2. 【微信Java开发 --1---番外1】在windows下,使用JAVA执行多条DOS命令+文件夹/路径中有空格怎么解决【目的是实现内容穿透外网】

    内网穿透外网的那一篇,参正集1 但是每次都要Ctrl+R 启动DOS窗口,也就是CMD,一句一句的去粘,略显繁琐. 所以将这些任务写在JAVA程序中,启动一次程序就可以实现[内网穿透]的功能,多好啊! ...

  3. hive脚本出现Error: java.lang.RuntimeException: Error in configuring object和Caused by: java.lang.IndexOutOfBoundsException: Index: 9, Size: 9

    是在reduce阶段报的错误,详细错误信息是 朱传豪 19:04:48 Diagnostic Messages for this Task: Error: java.lang.RuntimeExcep ...

  4. 04_Java面向对象特征之继承与多态

    1. 继承 Java继承的实现(只支持单继承,而不是多继承,但有接口的多实现) 多个类中存在相同属性和行为时,将这些内容抽取到单独一个类. 定义类时直接通过extends关键字指明要继承的父类.子类对 ...

  5. node body-parser

    var express = require('express'); var app = express(); var bodyParser = require('body-parser'); // p ...

  6. Python基础7- 流程控制之循环

    循环: 把一段代码重复性的执行N次,直到满足某个条件为止. 为了在合适的时候,停止重复执行,需要让程序出现满足停止循环的条件.Python中有三种循环(实质只有两种): while循环 for循环 嵌 ...

  7. HDU5726 GCD(二分 + ST表)

    题目 Source http://acm.hdu.edu.cn/showproblem.php?pid=5726 Description Give you a sequence of N(N≤100, ...

  8. Codeforces 567C Geometric Progression(思路)

    题目大概说给一个整数序列,问里面有几个包含三个数字的子序列ai,aj,ak,满足ai*k*k=aj*k=ak. 感觉很多种做法的样子,我想到这么一种: 枚举中间的aj,看它左边有多少个aj/k右边有多 ...

  9. ZOJ3195 Design the city(LCA)

    题目大概说给一棵树,每次询问三个点,问要把三个点连在一起的最少边权和是多少. 分几种情况..三个点LCA都相同,三个点有两对的LCA是某一点,三个点有两对的LCA各不相同...%……¥…… 画画图可以 ...

  10. BZOJ3566 : [SHOI2014]概率充电器

    选个根把无根树转化成有根树, 设f[i]表示i不通电的概率 则 答案为对于枚举树根root进行DP后1-f[root]的和 直接算是O(n^2)的,但是n有500000,所以不能过. 对于这样一棵以1 ...