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 ...
随机推荐
- 100个iOS开发/设计面试题汇总
常见问题 你昨天/这周学习了什么? 你为什么热衷于软件开发? 你对哪一种控制系统比较熟悉? 是否参与过GitHub项目? 是否参与过GitHub或其他同类型网站的iOS开源项目? 请描述一下你的iOS ...
- idea使用generator自动生成model、mapper、mapper.xml(转)
原文链接:http://www.mamicode.com/info-detail-445217.html TEP 0.在Intellij IDEA创建maven项目(本过程比较简单,略) STEP 1 ...
- Hadoop 重启各个节点
对于datanode可以在master中配置,然后在maste启动的时候,一并去启动这些节点 .对于死掉的节点,也可以通过以下命令启动 .重启挂掉的节点进入到 挂掉的机器 bin/hadoop-dae ...
- Embedded binary is not signed with the same certificate as the parent app
I face the same issue too,I solve it by this: First, I reCreate my team develop certificate(Because ...
- 理解Mach Port
参考文档: 1. http://robert.sesek.com/thoughts/2012/1/debugging_mach_ports.html 2. Mach 3 Kernel Interfac ...
- 06-图1 List Components
这题主要涉及到了队列,无向图的邻接矩阵表示,图的深度和广度优先搜索.又是糙哥,参考了他的程序(http://www.cnblogs.com/liangchao/p/4288807.html),主要是B ...
- C++ Frequently asking question
http://stackoverflow.com/questions/14295884/c-new-empty-project-how-to-create-it-add-main-method-and ...
- iOS常用正则表达式验证(手机号、密码格式、身份证号等)
#import @interfaceUtils : NSObject #pragma 正则匹配手机号 + (BOOL)checkTelNumber:(NSString*) telNumber; #pr ...
- XMPP即时通讯
XMPP:XMPP是基于XML的点对点通讯协议,The Extensible Messaging and Presence Protocol(可扩展通讯和表示协议). XMPP可用于服务类实时通讯,表 ...
- NSArray,NSSet,NSDictionary的遍历,基本使用集锦
NSArray *array = [NSArray arrayWithObjects:@"zhangsan",@"lisi",@"wangwu&quo ...