NBUT 1221 Intermediary
最短路,三进制状态压缩。
$dis[i][j]$表示到$i$节点,每个中介用了几次的情况下的最小花费,跑最短路即可。
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#include<string>
#include<iostream>
using namespace std; int n,m,q;
int e[],f[],r[]; struct X
{
int a,b,z,d;
int nx;
}ee[]; struct Y
{
int id,st,dis;
Y(int ID,int ST,int DIS)
{
id=ID;
st=ST;
dis=DIS;
} bool operator <(const Y&y) const
{
return dis>y.dis;
}
}; int h[], dis[][];
int t[]; void dij()
{
for(int i=;i<n;i++)
for(int j=;j<t[m];j++)
dis[i][j]=0x7FFFFFFF; dis[][]=;
priority_queue<Y>Q; Q.push(Y(,,)); while(!Q.empty())
{
Y q = Q.top(); Q.pop();
if(q.dis>dis[q.id][q.st]) continue;
if(q.id==n-)
{
printf("%d\n",q.dis);
return ;
} for(int i=h[q.id];i!=-;i=ee[i].nx)
{
int tmp=q.st;
for(int j=;j<m;j++) r[j]=tmp%,tmp/=; int cost = ee[i].d, v = ;
if(r[ee[i].z]==) cost += e[ee[i].z];
else if(r[ee[i].z]==) cost += f[ee[i].z],v=; if(q.dis+cost<dis[ee[i].b][q.st+v*t[ee[i].z]])
{
dis[ee[i].b][q.st+v*t[ee[i].z]] = q.dis+cost;
Q.push(Y(ee[i].b,q.st+v*t[ee[i].z],dis[ee[i].b][q.st+v*t[ee[i].z]]));
}
}
}
} int main()
{
t[]=; for(int i=;i<=;i++) t[i]=*t[i-]; while(~scanf("%d%d%d",&n,&m,&q))
{
for(int i=;i<m;i++) scanf("%d",&e[i]);
for(int i=;i<m;i++) scanf("%d",&f[i]); memset(h,-,sizeof h); for(int i=;i<=q;i++)
{
scanf("%d%d%d%d",&ee[i].a,&ee[i].b,&ee[i].z,&ee[i].d);
ee[i].nx = h[ee[i].a];
h[ee[i].a]=i;
} dij();
}
return ;
}
NBUT 1221 Intermediary的更多相关文章
- NBUT 1221 Intermediary 2010辽宁省赛
Time limit 1000 ms Memory limit 131072 kB It is widely known that any two strangers can get to know ...
- NBUT 1457 莫队算法 离散化
Sona Time Limit:5000MS Memory Limit:65535KB 64bit IO Format: Submit Status Practice NBUT 145 ...
- BZOJ 1221: [HNOI2001] 软件开发
1221: [HNOI2001] 软件开发 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 1428 Solved: 791[Submit][Stat ...
- ACM: NBUT 1107 盒子游戏 - 简单博弈
NBUT 1107 盒子游戏 Time Limit:1000MS Memory Limit:65535KB 64bit IO Format: Practice Appoint ...
- ACM: NBUT 1105 多连块拼图 - 水题 - 模拟
NBUT 1105 多连块拼图 Time Limit:1000MS Memory Limit:65535KB 64bit IO Format: Practice Appoint ...
- ACM: NBUT 1646 Internet of Lights and Switches - 二进制+map+vector
NBUT 1646 Internet of Lights and Switches Time Limit:5000MS Memory Limit:65535KB 64bit IO Fo ...
- ural 1221. Malevich Strikes Back!
1221. Malevich Strikes Back! Time limit: 1.0 secondMemory limit: 64 MB After the greatest success of ...
- 【BZOJ】1221: [HNOI2001] 软件开发(最小费用最大流)
http://www.lydsy.com/JudgeOnline/problem.php?id=1221 先吐槽一下,数组依旧开小了RE:在spfa中用了memset和<queue>的版本 ...
- NBUT 1525 Cow Xor(01字典树+前缀思想)
[1525] Cow Xor 时间限制: 2000 ms 内存限制: 65535 K 问题描述 农民约翰在喂奶牛的时候被另一个问题卡住了.他的所有N(1 <= N <= 100,000)个 ...
随机推荐
- springboot项目启动成功后执行一段代码的两种方式
springboot项目启动成功后执行一段代码的两种方式 实现ApplicationRunner接口 package com.lnjecit.lifecycle; import org.springf ...
- poi对excel的操作(二)
二.进阶的对象 1.CellType 枚举类 单元格类型 CellType.STRING---文本型 等 如何是指单元格类型:cell.setCellType(CellType.STRING) 2.C ...
- 学习 C++的用途,(前辈总结)
C++准确说是一门中级语言,介于汇编和高级语言之间吧,要求程序员了解计算机的内部数据存储.个人认为,作为学生还是花功夫学C++,因为<设计模式><数据结构>这些课程基本上还是C ...
- Codeforces 620C EDU C.Pearls in a Row ( set + greed )
C. Pearls in a Row There are n pearls in a row. Let's enumerate them with integers from 1 to n from ...
- [Luogu 1197] JSOI2008 星球大战
[Luogu 1197] JSOI2008 星球大战 我算是真的沦为联赛选手了. 并查集裸题. 比较麻烦的是删点. 但是从后往前加点就好操作很多. 所以考虑离线,先存图,然后没被删的点之间,有边就合并 ...
- Spring bean - scope详解
Scope是定义Spring如何创建bean的实例的. 在创建bean的时候可以带上scope属性,scope有下面几种类型. Singleton 这也是Spring默认的scope,表示Spring ...
- 【CODEVS】1034 家园
[算法]网络流-最大流(dinic) [题解] 飞船有可承载人数限制,地球为源点,月球为汇点,人像水流一样从以飞船上限为容量的边流向汇点. 人在各站点都面临着上船与否的选择,难以用DP解决最优策略,于 ...
- 面向对象 ( OO ) 的程序设计——理解对象
本文地址:http://www.cnblogs.com/veinyin/p/7607938.html 1 创建自定义对象 创建自定义对象的最简单方法为创建 Object 的实例,并添加属性方法,也可 ...
- vista风格的cms企业html后台管理系统模板——后台
链接:http://pan.baidu.com/s/1c1Cv99e 密码:20yz
- 使用qt写的简单的图片浏览器
功能特别简单,支持png,jpg,bmp,gif文件,支持自适应窗口大小,支持放大缩小,旋转功能还有点问题,支持上下按键选择图片 因为初学qt,所以很多东西都不太会,而且c++学的不是太好,没有怎么使 ...