【BZOJ2662】【BeiJing wc2012】冻结 分层图 裸的!
我都不好意思发题解了,看这篇博吧。(飞行路线的,基本一样)
http://blog.csdn.net/vmurder/article/details/40075989
同学做了好久。我害怕题里有坑,又重写了一遍~~~
7分钟。都不乐意測例子測点就A了啊哈。
- #include <queue>
- #include <cstdio>
- #include <cstring>
- #include <algorithm>
- #define N 55
- #define M 1010
- #define K 50
- #define inf 0x3f3f3f3f
- using namespace std;
- struct KSD
- {
- int v,len,next;
- }e[M<<1];
- int head[N],cnt;
- void add(int u,int v,int len)
- {
- cnt++;
- e[cnt].v=v;
- e[cnt].len=len;
- e[cnt].next=head[u];
- head[u]=cnt;
- }
- struct Lux
- {
- int x,y;
- Lux(int a,int b):x(a),y(b){}
- Lux(){}
- };
- int n,m,p;
- int dist[K][N],s,t;
- bool in[K][N];
- int spfa()
- {
- int i,v;
- queue<Lux>q;
- memset(dist,0x3f,sizeof(dist));
- dist[0][s]=0;
- in[0][s]=1;
- q.push(Lux(0,s));
- while(!q.empty())
- {
- Lux U=q.front();q.pop();
- for(i=head[U.y];i;i=e[i].next)
- {
- v=e[i].v;
- if(dist[U.x][v]>dist[U.x][U.y]+e[i].len)
- {
- dist[U.x][v]=dist[U.x][U.y]+e[i].len;
- if(!in[U.x][v])
- {
- in[U.x][v]=1;
- q.push(Lux(U.x,v));
- }
- }
- }
- if(U.x<p)for(i=head[U.y];i;i=e[i].next)
- {
- v=e[i].v;
- if(dist[U.x+1][v]>dist[U.x][U.y]+(e[i].len>>1))
- {
- dist[U.x+1][v]=dist[U.x][U.y]+(e[i].len>>1);
- if(!in[U.x+1][v])
- {
- in[U.x+1][v]=1;
- q.push(Lux(U.x+1,v));
- }
- }
- }
- }
- int ret=inf;
- for(i=0;i<=p;i++)ret=min(ret,dist[i][t]);
- return ret;
- }
- int main()
- {
- int i,j,k;
- int a,b,c;
- scanf("%d%d%d",&n,&m,&p);
- for(i=1;i<=m;i++)
- {
- scanf("%d%d%d",&a,&b,&c);
- add(a,b,c);
- add(b,a,c);
- }
- s=1,t=n;
- printf("%d\n",spfa());
- return 0;
- }
【BZOJ2662】【BeiJing wc2012】冻结 分层图 裸的!的更多相关文章
- BZOJ2662[BeiJing wc2012]冻结——分层图最短路
题目描述 “我要成为魔法少女!” “那么,以灵魂为代价,你希望得到什么?” “我要将有关魔法和奇迹的一切,封印于卡片之中„„” 在这个愿望被实现以后的世界里,人们享受着魔法卡片(Spe ...
- [bzoj2662 BeiJing wc2012] 冻结 (分层图+最短路)
传送门 Description "我要成为魔法少女!" "那么,以灵魂为代价,你希望得到什么?" "我要将有关魔法和奇迹的一切,封印于卡片之中„„&q ...
- bzoj2662 [BeiJing wc2012]冻结 ——分层图
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2662 分层图: 我也不知道我写的是不是 bfs (dijkstra?). 代码如下: #in ...
- 【bzoj2662】[BeiJing wc2012]冻结 分层图Spfa
原文地址:http://www.cnblogs.com/GXZlegend 题目描述 “我要成为魔法少女!” “那么,以灵魂为代价,你希望得到什么?” “我要将有关魔法和奇迹的一切,封印于卡片之中„„ ...
- bzoj 2662 [BeiJing wc2012]冻结——分层图
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2662 这种的都是分层图. #include<iostream> #include ...
- BZOJ2662: [BeiJing wc2012]冻结 spfa+分层图
Description “我要成为魔法少女!” “那么,以灵魂为代价,你希望得到什么?” “我要将有关魔法和奇迹的一切,封印于卡片之中„„” 在这个愿望被实现以后的世界里,人们享 ...
- 【最短路】【Heap-Dijkstra】【分层图】bzoj2662 [BeiJing wc2012]冻结
裸的分层图最短路. #include<cstdio> #include<cstring> #include<queue> #include<algorithm ...
- BZOJ2662 [BeiJing wc2012]冻结
网上的题解都是分层图+spfa或者dijkstra 我觉得dijk太难写了,懒得写,看了一下数据范围$N=50$,这显然是出题人勾引人犯罪 我决定使用floyd的做法,令$f[i][j][t](k)$ ...
- bzoj2662: [BeiJing wc2012]冻结 最短路 建图
好久没有1A题啦♪(^∇^*) 一个sb建图,我居然调样例调了10min 看起来是双向边,其实在建图的时候要当成有向图, 否则他会时间倒流(233) 把每个点裂成k个点,然后把每条边裂成4条边(正向反 ...
随机推荐
- 机器学习之路: python 朴素贝叶斯分类器 MultinomialNB 预测新闻类别
使用python3 学习朴素贝叶斯分类api 设计到字符串提取特征向量 欢迎来到我的git下载源代码: https://github.com/linyi0604/MachineLearning fro ...
- POJ 1469 COURSES 二分图最大匹配 二分图
http://poj.org/problem?id=1469 这道题我绝壁写过但是以前没有mark过二分图最大匹配的代码mark一下. 匈牙利 O(mn) #include<cstdio> ...
- loj6300 「CodePlus 2018 3 月赛」博弈论与概率统计
link 题意: A和B玩游戏,每轮A赢的概率为p.现在有T组询问,已知A赢了n轮输了m轮,没有平局,赢一局A得分+1,输一局得分-1,问A得分期望值? $n+m,T\leq 2.5\times 10 ...
- PAT(Basic Level)--个位数统计
输入一个不超过1000位的整数,计算每个数字出现的次数. 一道十分简单的题目,最开始以为Java的String没有计算长度的方法,还想了半天,而且还用HashMap做了一次,代码特别长,看了别人的代码 ...
- Codeforces Round #288 (Div. 2) B. Anton and currency you all know 贪心
B. Anton and currency you all know time limit per test 0.5 seconds memory limit per test 256 megabyt ...
- thrift 安装 make 失败 ar: .libs/ThriftTest_constants.o: No such file or directory
$wget http://mirrors.cnnic.cn/apache/thrift/0.9.1/thrift-0.9.1.tar.gz $tar zxvf thrift-0.9.1.tar.gz ...
- Install WordPress Plugins without FTP Access
WordPress will only prompt you for your FTP connection information while trying to install plugins o ...
- wrote a programming language
https://medium.freecodecamp.org/the-programming-language-pipeline-91d3f449c919
- GDB高级用法
http://blog.csdn.net/wwwsq/article/details/7086151
- poj 1028 Web Navigation(模拟)
题目链接:http://poj.org/problem? id=1028 Description Standard web browsers contain features to move back ...