第一次知道。。原来spfa还可以这样写。。。用pq。。。

只需要直接求拐点即可,数据小想怎么搞就怎么搞

(话说怎么这么裸的最短路都写不出来了233)

 1 /**************************************************************
 2     Problem: 3393
 3     User: rausen
 4     Language: C++
 5     Result: Accepted
 6     Time:36 ms
 7     Memory:1156 kb
 8 ****************************************************************/
 9
10 #include <cstdio>
11 #include <cstring>
12 #include <algorithm>
13 #include <queue>
14
15 using namespace std;
16 const int dx[4] = {0, 1, 0, -1};
17 const int dy[4] = {1, 0, -1, 0};
18 const int N = 105;
19 const int inf = (int) 1e9;
20
21 struct data {
22     int x, y, to, dis;
23     data() {}
24     data(int _x, int _y, int _t, int _d) : x(_x), y(_y), to(_t), dis(_d) {}
25
26     inline bool operator < (const data &b) const {
27         return dis > b.dis;
28     }
29 };
30
31 int n, m, ans;
32 int sx, sy, ex, ey;
33 int dis[N][N][4], w[N][N];
34 priority_queue <data> q;
35
36 inline bool in(int x, int y) {
37     return 1 <= x && x <= n && 1 <= y && y <= m;
38 }
39
40 int main() {
41     int i, j;
42     char ch;
43     scanf("%d%d", &m, &n);
44     for (i = 1; i <= n; ++i)
45         for (j = 1; j <= m; ++j) {
46         ch = getchar();
47         while (ch != 'C' && ch != '.' && ch != '*')
48             ch = getchar();
49         if (ch == '*') w[i][j] = 1;
50         if (ch == 'C')
51             if (!sx) sx = i, sy = j;
52             else ex = i, ey = j;
53     }
54     memset(dis, 127 / 3, sizeof(dis));
55     for (i = 0; i < 4; ++i) {
56         q.push(data(sx, sy, i, 0));
57         dis[sx][sy][i] = 0;
58     }
59
60     int x, y, k, x1, y1;
61     while (!q.empty()) {
62         x1 = x = q.top().x, y1 = y = q.top().y, k = q.top().to;
63         while (in(x1 += dx[k], y1 += dy[k]) && !w[x1][y1] && dis[x1][y1][k] > dis[x][y][k]) {
64             dis[x1][y1][k] = dis[x][y][k];
65             q.push(data(x1, y1, k, dis[x][y][k]));
66         }
67         for (i = 0; i < 4; ++i)
68             if (dis[x][y][i] > q.top().dis + 1) {
69                 dis[x][y][i] = q.top().dis + 1;
70                 q.push(data(x, y, i, dis[x][y][i]));
71             }
72         q.pop();
73     }
74     for (i = 0, ans = inf; i < 4; ++i)
75         ans = min(ans, dis[ex][ey][i]);
76     printf("%d\n", ans);
77     return 0;
78 }

View Code

转载于:https://www.cnblogs.com/rausen/p/4138013.html

BZOJ3393 [Usaco2009 Jan]Laserphones 激光通讯相关推荐

  1. bzoj3396[Usaco2009 Jan]Total flow 水流*

    bzoj3396[Usaco2009 Jan]Total flow 水流 题意: 求无环图的最大流.边数≤700. 题解: 管它有没有环.注意本题的节点标号既有大写字母,也有小写字母. 代码: 1 # ...

  2. 1574: [Usaco2009 Jan]地震损坏Damage

    1574: [Usaco2009 Jan]地震损坏Damage Time Limit: 10 Sec  Memory Limit: 64 MB Submit: 425  Solved: 232 [Su ...

  3. bzoj 3396: [Usaco2009 Jan]Total flow 水流(最大流)

    3396: [Usaco2009 Jan]Total flow 水流 Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 615  Solved: 295 ...

  4. bzoj 3394: [Usaco2009 Jan]Best Spot 最佳牧场(floyd)

    3394: [Usaco2009 Jan]Best Spot 最佳牧场 Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 98  Solved: 76 [ ...

  5. 【BZOJ】1574: [Usaco2009 Jan]地震损坏Damage

    [算法]搜索 [题意]给定无向图,现在可能有一些点已经被删除,只给出信息是c个点不能到达结点1,求最少的不能到达结点1的个数(含已删除点). [题解] 真是一道奥妙重重的题目. 每个点不能到达结点1, ...

  6. BZOJ1575: [Usaco2009 Jan]气象牛Baric

    n<=100个数字,选最少的个数使"误差"少于E并输出选该个数下最小的"误差".误差定义: 对于任何测量结果子集,每一个非此子集中的结果都会产生误差.总误 ...

  7. BZOJ1576: [Usaco2009 Jan]安全路经Travel(树链剖分)

    Description Input * 第一行: 两个空格分开的数, N和M * 第2..M+1行: 三个空格分开的数a_i, b_i,和t_i Output * 第1..N-1行: 第i行包含一个数 ...

  8. P1574: [Usaco2009 Jan]地震损坏Damage

    卧槽卧槽卧槽,这道水题竟然让我WA了两遍!!评测系统卡了然后手贱又提交了一次,然后就悲催了呜呜.. 把与不能回家但牛棚完好的牛相邻的牛棚赋值为不能走(false),可以证明,如果该牛回不了家,则周围一 ...

  9. 【BZOJ】3396: [Usaco2009 Jan]Total flow 水流 (最大流)

    http://www.lydsy.com/JudgeOnline/problem.php?id=3396 裸的最大流跑过.. #include <cstdio> #include < ...

最新文章

  1. 归于软银帐下,ARM需要接受的变与不变
  2. 交换机与路由器在网路中所扮演的角色—Vecloud微云
  3. aarch64的TCR寄存器介绍
  4. UI自学宝典,完整UI学习线路图
  5. windows server 2003 r2 64位web服务器安装配置注意事项
  6. 关于async与await的FAQ 转
  7. NLP太难学了!?吃透NLP的方法来拿走
  8. ICML2020 | 伯克利提出大模型提升Transformer的训练和推理效率
  9. 红米Note 7 Pro彩排PPT露出:可降低90%入水量?
  10. S.Finance已上线收益稳定币UU
  11. Django项目实践2 - Django模板语言(常用语法规则)
  12. 如何在CSDN中免费下载资料
  13. phpspider 简单使用
  14. 计算机音乐超级马丽,你与你的音乐梦想,只差一台数学计算器
  15. matlab图论软件包,MATLAB_bgl_toolbox 图论通用工具箱总汇:GraphTheory for St 247万源代码下载- www.pudn.com...
  16. 关于jupyter notebook闪退问题【我真真的够了,大家以后不要乱捣鼓电脑了,绝了】
  17. 力扣:探索初级算法——数组篇——有效的数独
  18. CrazyTalk 8 中文版 照片会说话动画制作 带动作脚本 点头眨眼动画制作
  19. JAVA组合框怎么添加加减乘除,[C#]组合框设计windows加减乘除简单计算器应用
  20. 通过MACE在Android手机上部署深度学习模型

热门文章

  1. Mybatis-Plus一个新的报错:数据库表名与SQL的关键字冲突!!!
  2. 就mysql command line client刚输入密码立马闪一下退出问题的解决方案
  3. ajax form不回调函数,jQuery ajax form提交在IE8下不执行回调函数
  4. spring单元测试无法注入bean_2019年,最新的Spring 面试108题 “ 系列 ”,附带答案.........
  5. html设置页面大小_如何将Word文档页面大小设置为16开?
  6. mybatis 配置文件中set丢失逗号
  7. CentOS 7.X 安装 Gitlab 笔记
  8. sharepoint模拟用户
  9. Rook存储:Kubernetes中最优秀的存储
  10. SpringBoot配置属性之Server