POJ 1062 dij
一道读题读的不明所以的题...
每个人只能接受和自己等级差距不超过m的人进行交易 包括间接交易
所以我们可以枚举每一个长度为m的围绕着酋长的等级区间 每次都对这个等级区间内的人进行操作 求dis[1]
在这里的建图方式是很难得的灵光一现呢..
将0点作为源点 每一个物品的本身直接购买的价值设为初始值 对它们进行所给等级区间允许内的松弛操作 找出其中最小的dis[1]
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<map>
#include<math.h>
#include<queue>
#include<iostream>
using namespace std;
int m,n;
int dis[105];
int a[105];
struct node
{
int v;
int nex;
int w;
};
node b[30050];
int point [105];
int level[105];
bool vis[105];
int cnt;
void init()
{
cnt=0;
for(int i=1; i<=n; i++)
point[i]=-1;
for(int i=1; i<=n; i++)
vis[i]=true;
}
void add(int u,int v,int w)
{
b[cnt].v=v;
b[cnt].w=w;
b[cnt].nex=point[u];
point[u]=cnt;
cnt++;
}
void dij(int l,int r)
{
for(int i=1; i<=n; i++)
{
int p=-1;
int minn=999999999;
for(int k=1; k<=n; k++)
{
if(vis[k]&&minn>dis[k])
{
minn=dis[k];
p=k;
}
}
if(p==-1)
return ;
vis[p]=false;
for(int tt=point[p]; tt!=-1; tt=b[tt].nex)
{
int v=b[tt].v;
int w=b[tt].w;
if(level[v]>=l&&level[v]<=r&&level[p]>=l&&level[p]<=r&&vis[v])
{
if(dis[v]>w+dis[p])
{
dis[v]=dis[p]+w;
}
}
}
}
}
int main()
{
while(~scanf("%d%d",&m,&n))
{
init();
for(int i=1; i<=n; i++)
{
int p;
int l,x;
scanf("%d%d%d",&p,&l,&x);
level[i]=l;
a[i]=p;
for(int k=1; k<=x; k++)
{
int d;
int w;
scanf("%d%d",&d,&w);
add(d,i,w);
}
}
for(int i=1; i<=n; i++)
dis[i]=a[i];
int ans=999999999;
for(int l=level[1]-m; l<=level[1]; l++)
{
int r=l+m;
for(int i=1; i<=n; i++)
vis[i]=true;
for(int i=1; i<=n; i++)
dis[i]=a[i];
dij(l,r);
if(ans>dis[1])
ans=dis[1];
}
printf("%d\n",ans);
}
}
POJ 1062 dij的更多相关文章
- 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 昂贵的聘礼(dij+邻接矩阵)
( ̄▽ ̄)" #include<iostream> #include<cstdio> #include<cstring> #include<cstd ...
- (最短路 dijkstra)昂贵的聘礼 -- poj -- 1062
链接: http://poj.org/problem?id=1062 昂贵的聘礼 Time Limit: 1000MS Memory Limit: 10000K Total Submissions ...
- POJ 1062 限制点
http://poj.org/problem?id=1062 昂贵的聘礼 Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 50 ...
- POJ 1062 ( dijkstra )
http://poj.org/problem?id=1062 一个中文题,一个多月之前我做过,当时我是用搜索写的,不过苦于卡在无法确定等级关系,所以就错了. 看了别人的博客后,我还是不是很理解所谓的枚 ...
- POJ 1062 昂贵的聘礼 最短路 难度:0
http://poj.org/problem?id=1062 #include <iostream> #include <cstring> #include <queue ...
随机推荐
- 修改PHP网站默认首页
一般默认的首页文件是index.php index.php3 index.html index.htm之类的,要想修改为myNewIndex.php, 进入服务器Apache目录,找到httpd.co ...
- July 22nd, Week 30th Friday, 2016
Love means never having to say you are sorry. 爱就是永远不必说对不起. Love means knowing each other deeply, the ...
- icon font字体图标字库汇总
最近在研究icon font图标字库,找了一些比较好的在线字库.大都是开源的,而且各有特色! 阿里icon font字库 http://www.iconfont.cn/ 这个是阿里妈妈M2UX的一个i ...
- CodeForces Gym 100500A A. Poetry Challenge DFS
Problem A. Poetry Challenge Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/10 ...
- 使用pm2常见问题
一.日志 1.pm2 的log怎么查看?(安装pm2后默认日志的路径为~/.pm2/),可以通过pm2 show (name)来查看某个进程下的日志地址 2.修改日志的输出路径,通过写一个程序启动的配 ...
- SQLServer备份脚本
企业管理器--管理--SQL Server代理--右键作业--新建作业--"常规"项中输入作业名称--"步骤"项--新建--"步骤名"中输入 ...
- Linphone iOS客户端编译时打开G729支持
Assuming you were able to compile the SDK and the linphone XCode project, here is what you need to d ...
- synchronized的理解
用法解释 synchronized是Java中的关键字,是一种同步锁.它修饰的对象有以下几种: 1. 修饰一个代码块,被修饰的代码块称为同步语句块,其作用的范围是大括号{}括起来的代码,作用的对象是调 ...
- js:数据结构笔记3--栈
栈是一种特殊的列表,数据结构为LIFO: 定义: function Stack() { this.dataStore = []; this.top = 0; this.push = push; thi ...
- 在JavaScript中,this关键字指什么?
指向对象.window.方法. 例子1 function a(){//当前调用栈是a,因此a的调用位置是全局作用域 console.log('a'); b();// b的调用位置 } function ...