bzoj1624 [Usaco2008 Open] Clear And Present Danger 寻宝之路
Description
Input
Output
Sample Input
1
2
1
3
0 5 1
5 0 2
1 2 0
INPUT DETAILS:
There are 3 islands and the treasure map requires Farmer John to
visit a sequence of 4 islands in order: island 1, island 2, island
1 again, and finally island 3. The danger ratings of the paths are
given: the paths (1, 2); (2, 3); (3, 1) and the reverse paths have
danger ratings of 5, 2, and 1, respectively.
Sample Output
OUTPUT DETAILS:
He can get the treasure with a total danger of 7 by traveling in
the sequence of islands 1, 3, 2, 3, 1, and 3. The cow map's requirement
(1, 2, 1, and 3) is satisfied by this route. We avoid the path
between islands 1 and 2 because it has a large danger rating.
用Floyd预处理出两两之间的最小边权和,然后按题目给的顺序走一遍
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<cstring>
using namespace std;
inline int read()
{
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x*=10;x+=ch-'0';ch=getchar();}
return x*f;
}
int dist[101][101];
int a[10001];
int ans;
int main()
{
int n=read(),m=read();
for (int i=1;i<=m;i++)
a[i]=read();
for (int i=1;i<=n;i++)
for (int j=1;j<=n;j++)
dist[i][j]=read();
for (int k=1;k<=n;k++)
for (int i=1;i<=n;i++)
for (int j=1;j<=n;j++)
dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);
for (int i=2;i<=m;i++)ans+=dist[a[i-1]][a[i]];
cout<<ans;
}
bzoj1624 [Usaco2008 Open] Clear And Present Danger 寻宝之路的更多相关文章
- Bzoj 1624: [Usaco2008 Open] Clear And Present Danger 寻宝之路 最短路,floyd
1624: [Usaco2008 Open] Clear And Present Danger 寻宝之路 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 5 ...
- BZOJ 1624: [Usaco2008 Open] Clear And Present Danger 寻宝之路( 最短路 )
直接floyd.. ----------------------------------------------------------------------- #include<cstdio ...
- 1624: [Usaco2008 Open] Clear And Present Danger 寻宝之路
1624: [Usaco2008 Open] Clear And Present Danger 寻宝之路 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 3 ...
- [Usaco2008 Open] Clear And Present Danger 寻宝之路[最短路][水]
Description 农夫约翰正驾驶一条小艇在牛勒比海上航行. 海上有N(1≤N≤100)个岛屿,用1到N编号.约翰从1号小岛出发,最后到达N号小岛.一 张藏宝图上说,如果他的路程上 ...
- 【BZOJ】1624: [Usaco2008 Open] Clear And Present Danger 寻宝之路(floyd)
http://www.lydsy.com/JudgeOnline/problem.php?id=1624 一开始我打算一个个最短路................................. 然 ...
- [图论训练]BZOJ 1624: [Usaco2008 Open] Clear And Present Danger 寻宝之路【floyd】
Description 农夫约翰正驾驶一条小艇在牛勒比海上航行. 海上有N(1≤N≤100)个岛屿,用1到N编号.约翰从1号小岛出发,最后到达N号小岛.一 张藏宝图上说,如果他的路程上 ...
- BZOJ 1624: [Usaco2008 Open] Clear And Present Danger 寻宝之路
Description 农夫约翰正驾驶一条小艇在牛勒比海上航行. 海上有N(1≤N≤100)个岛屿,用1到N编号.约翰从1号小岛出发,最后到达N号小岛.一 张藏宝图上说,如果他的路程上经过的小岛依次出 ...
- BZOJ 1624 [Usaco2008 Open] Clear And Present Danger 寻宝之路:floyd
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1624 题意: 农夫约翰正驾驶一条小艇在牛勒比海上航行. 海上有N(1≤N≤100)个岛屿, ...
- bzoj 1624: [Usaco2008 Open] Clear And Present Danger 寻宝之路【Floyd】
弗洛伊德之后按序列加起来即可 #include<iostream> #include<cstdio> #include<algorithm> using names ...
随机推荐
- Linux grep 命令中的正则表达式详解
在 Linux .类 Unix 系统中我该如何使用 Grep 命令的正则表达式呢? Linux 附带有 GNU grep 命令工具,它支持扩展正则表达式(extended regular expres ...
- Objective-C实现变参函数
原文:http://www.tanhao.me/pieces/1104.html NSLog(NSString *format, ...) + (id)arrayWithObjects:(id ...
- 继承PictureBox显示GIF的自定义控件实现
处理GIF部分 using System; using System.Collections.Generic; using System.Linq; using System.Text; using ...
- paip.提升用户体验---c++ qt 取消gcc编译的警告信息.txt
paip.提升用户体验---c++ qt 取消gcc编译的警告信息.txt 作者Attilax , EMAIL:1466519819@qq.com 来源:attilax的专栏 地址:http:// ...
- 百度之星资格赛 hdu 4826 Labyrinth 动态规划
/********************* Problem Description 是一仅仅喜欢探险的熊.一次偶然落进了一个m*n矩阵的迷宫,该迷宫仅仅能从矩阵左上角第一个方格開始走,仅仅有走到右上 ...
- cocos2d-x 2.x 图层特效Effect(转)
CCSprite* sp = CCSprite::create("Default.png"); sp->setPosition(ccp(, )); addChild(sp); ...
- 腾讯云(centos)上安装apache
安装 yun install httpd 随系统自启动 chkconfig httpd on 修改/etc/httpd/conf/httpd.conf文件 #修改WWW目录为自己的目录 Dcoumen ...
- 使用VS Code开发TypeScript--定义变量推荐使用let
使用VS Code开发TypeScript--定义变量推荐使用let 目录 作用域规则 JavaScript的严格模式 let与var的区别 作用域规则 一直以来我们都是通过var关键字定义JavaS ...
- IPointCollection,ISegmentCollection和IGeometryCollection
Engine 提供了三个主要的几何图形集合接口用于对几何对象的操作,分别是 IPointCollection,ISegmentCollection 和 IGeometryCollection,这些接口 ...
- js判断是否微信浏览器打开
function is_weixn(){ var ua = navigator.userAgent.toLowerCase(); if(ua.match(/MicroMessenger/i)==&qu ...