kuangbin_ShortPath M (POJ 1062)
提出了一个错误的算法 以为能优化到只运行两次dij
然而我还是too naive 还是乖乖dij n 次吧...
#include <iostream>
#include <string>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <queue>
#include <vector>
#include <set>
#include <algorithm>
#define INF 0x3F3F3F3F
using namespace std; typedef pair<int, int> pii;
struct cmp{
bool operator () (const pii a, const pii b){
return a.first > b.first;
}
}; int map[][], val[][], lev[];
int m, n; int dij()
{
int dist[];
priority_queue<pii, vector<pii>, cmp> q;
memset(dist, 0x3f, sizeof dist);
dist[] = ;
q.push(make_pair(, ));
while(!q.empty()){
pii u = q.top();
q.pop();
if(u.first > dist[u.second]) continue;
for(int i = ; i <= n; i++){
if(dist[i] > dist[u.second] + val[u.second][i]){
dist[i] = dist[u.second] + val[u.second][i];
q.push(make_pair(dist[i], i));
}
}
}
return dist[];
} int main()
{
memset(map, 0x3f, sizeof val);
scanf("%d%d", &m, &n);
for(int i = ; i <= n; i++){
int x, y, p;
scanf("%d%d%d", &map[][i], &lev[i], &x);
while(x--){
scanf("%d%d", &y, &p);
map[y][i] = p;
}
}
int ans = INF;
for(int i = ; i <= m; i++){
memset(val, 0x3f, sizeof val);
for(int x = ; x <= n; x++){
if(x == || (lev[x] >= lev[] - m + i && lev[x] <= lev[] + i)){
for(int y = ; y <= n; y++){
if(lev[y] >= lev[] - m + i && lev[y] <= lev[] + i){
val[x][y] = map[x][y];
}
}
}
}
ans = min(dij(), ans);
//printf("%d ~ %d : %d\n", lev[1] - m + i, lev[1] + i, ans);
}
printf("%d\n", ans);
return ;
}
kuangbin_ShortPath M (POJ 1062)的更多相关文章
- POJ 1062 昂贵的聘礼
C - 昂贵的聘礼 Time Limit:1000MS Memory Limit:10000KB 64bit IO Format:%I64d & %I64u Submit St ...
- 最短路(Dijkstra) POJ 1062 昂贵的聘礼
题目传送门 /* 最短路:Dijkstra算法,首先依照等级差距枚举“删除”某些点,即used,然后分别从该点出发生成最短路 更新每个点的最短路的最小值 注意:国王的等级不一定是最高的:) */ #i ...
- POJ 1062 昂贵的聘礼(图论,最短路径)
POJ 1062 昂贵的聘礼(图论,最短路径) Description 年轻的探险家来到了一个印第安部落里.在那里他和酋长的女儿相爱了,于是便向酋长去求亲.酋长要他用10000个金币作为聘礼才答应把女 ...
- 最短路POJ 1062 昂贵的聘礼
C - 昂贵的聘礼 Time Limit:1000MS Memory Limit:10000KB 64bit IO Format:%I64d & %I64u Submit St ...
- POJ 1062 ( dijkstra )
http://poj.org/problem?id=1062 一个中文题,一个多月之前我做过,当时我是用搜索写的,不过苦于卡在无法确定等级关系,所以就错了. 看了别人的博客后,我还是不是很理解所谓的枚 ...
- POJ 1062 昂贵的聘礼 最短路 难度:0
http://poj.org/problem?id=1062 #include <iostream> #include <cstring> #include <queue ...
- poj 1062(有限制的最短路)
题目链接:http://poj.org/problem?id=1062 思路:要求对于最短路上的点,不能出现等级之差大于m,于是我们可以枚举,假设酋长的等级为level,于是这个区间范围[level- ...
- poj 1062 昂贵的聘礼(最短路 dijk+枚举)
终于A 了,这题做着真麻烦 题目:http://poj.org/problem?id=1062 dijk 一般用于正权有向图 此题的关键在于等级限制的处理,最好的办法是采用枚举,即假设酋长等级为5,等 ...
- (最短路 dijkstra)昂贵的聘礼 -- poj -- 1062
链接: http://poj.org/problem?id=1062 昂贵的聘礼 Time Limit: 1000MS Memory Limit: 10000K Total Submissions ...
随机推荐
- 框架之 spring
spring有两大特性,其一为ioc,其二为aop 1.ioc的理解 ioc为依赖注入,他的好处就是把创建对象的权利交给spring去管理,这样的好处是 将应用程序中的对象解耦,传统的方式程序中的对象 ...
- [网络技术]VPN设置
1.解决VPN服务器默认路由困扰 现在移动办公已经变得家常便饭,每次外出出差办公需要访问单位的内网服务器时,该怎么办呢?相信很多人都想到了VPN连接!的确,使用VPN连接, 我们可以利用现成的Inte ...
- [转]理解WSRF之一 使用WS-ResourceProperties (整理自IBM网站)
理解 WSRF第1部分-使用 WS-ResourceProperties 本 教程是一个由 4 部分组成的系列文章中的第 1 部分,该系列介绍 WSRF(Web Services Resource ...
- SharePoint开发 - 使用Session(代码修改webconfig)
博客地址 http://blog.csdn.net/foxdave SharePoint启用Session可以使用Powershell,戳这里:可以修改webconfig. 本篇叙述的重点是通过fea ...
- Ubuntu 14.10 下设置时间同步
在启动HBase机群的时候,发现了一个错误,因为机群时间不同步导致,所以要同步集群时间. Linux的时间分为System Clock(系统时间)和Real Time Clock (硬件时间,简称RT ...
- type safe printf
在书里看到的,摘录如下: #include <iostream> #include <stdexcept> template<class T> struct is_ ...
- 【LeetCode OJ】Sum Root to Leaf Numbers
# Definition for a binary tree node # class TreeNode: # def __init__(self, x): # self.val = x # self ...
- mysql 远程连接失败(linux)
主要有三个原因:1.mysql授权表里没有远程机器的权限,及需要在授权表mysql.user添加grant all privileges on *.* to 'root'@'远程登陆IP' ident ...
- HDU 1622
http://acm.hdu.edu.cn/showproblem.php?pid=1622 白书上6.3.2二叉树层次遍历的例题,层次遍历用bfs,建立二叉树,很基础的题目 #include < ...
- shell MAC 地址 校验
/*************************************************************************************** * shell MAC ...