HDU 5636 Shortest Path(Floyd)
题目链接 HDU5636
n个点,其中编号相邻的两个点之间都有一条长度为1的边,然后除此之外还有3条长度为1的边。
m个询问,每次询问求两个点之前的最短路。
我们把这三条边的6个点两两算最短路,
然后询问的时候用这6个点的距离来更新答案就可以了。
(不过听说好像有更好的方法,先占个坑)
时间复杂度$O(216m)$
#include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for (int i(a); i <= (b); ++i)
#define dec(i, a, b) for (int i(a); i >= (b); --i) typedef long long LL; const LL mod = 1e9 + 7; int T;
int n, m;
int a[10];
int b[10][10];
int d;
LL ans, cnt; int main(){ scanf("%d", &T);
while (T--){
scanf("%d%d", &n, &m);
rep(i, 1, 6) scanf("%d", a + i);
ans = 0;
cnt = 0; rep(i, 1, 6) rep(j, 1, 6) b[i][j] = abs(a[i] - a[j]); b[1][2] = b[2][1] = 1;
b[3][4] = b[4][3] = 1;
b[5][6] = b[6][5] = 1; rep(k, 1, 6) rep(i, 1, 6) rep(j, 1, 6)
b[i][j] = min(b[i][j], b[i][k] + b[k][j]); for (; m--; ){
scanf("%d%d", &a[7], &a[8]);
d = abs(a[7] - a[8]);
rep(i, 1, 6) rep(j, 1, 6)
d = min(d, abs(a[i] - a[7]) + abs(a[j] - a[8]) + b[i][j]); (ans += (++cnt) * (LL)d) %= mod;
}
printf("%lld\n", ans);
} return 0;
}
HDU 5636 Shortest Path(Floyd)的更多相关文章
- hdu 3631 Shortest Path(Floyd)
题目链接:pid=3631" style="font-size:18px">http://acm.hdu.edu.cn/showproblem.php?pid=36 ...
- HDU-3631 Shortest Path (floyd)
Description When YY was a boy and LMY was a girl, they trained for NOI (National Olympiad in Informa ...
- HDU 5636 Shortest Path 暴力
Shortest Path 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5636 Description There is a path graph ...
- Shortest Path(hdu5636)
Shortest Path Accepts: 40 Submissions: 610 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: ...
- HDU 5636 Shortest Path(Floyed,枚举)
Shortest Path Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) Tot ...
- HDU 5636 Shortest Path
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5636 题解: 1.暴力枚举: #include<cmath> #include<c ...
- HDU 5636 Shortest Path 分治+搜索剪枝
题意:bc round 74 分析(官方题解): 你可以选择分类讨论, 但是估计可能会写漏一些地方. 只要抽出新增边的端点作为关键点, 建立一个新图, 然后跑一遍floyd就好了. 复杂度大概O(6^ ...
- HDU - 1973 - Prime Path (BFS)
Prime Path Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...
- HDU ACM 1869 六度分离(Floyd)
六度分离 Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
随机推荐
- orcal中创建和删除表空间和用户
1.创建表空间 create tablespace NW_DATA logging datafile 'F:\oracle\product\10.2.0\oradata\nwdb\NW_DATA.db ...
- 使用Microsoft Hadoop(一)
To run this program, stage some data in HDFS: 1. create a text file called input.txt that has one in ...
- 51nod——1174 区间中最大的数(ST)
题目链接 给出一个有N个数的序列,编号0 - N - 1.进行Q次查询,查询编号i至j的所有数中,最大的数是多少. 例如: 1 7 6 3 1.i = 1, j = 3,对应的数为7 6 3,最大的数 ...
- C++高精度乘法
#include <cstdio> #include <iostream> #include <algorithm> void highPrecision (int ...
- CSS 文本下划线 text-decoration
定义和用法 text-decoration 属性规定添加到文本的修饰. 可能的值 值 描述 none 默认.定义标准的文本. underline 定义文本下的一条线. overline 定义文本上 ...
- (转)WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!
[root@bak1 bak]# scp gwsyj.sql.gz root@192.168.21.65:/data/dbdata/ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ...
- LeetCode(105) Construct Binary Tree from Preorder and Inorder Traversal
题目 Given preorder and inorder traversal of a tree, construct the binary tree. Note: You may assume t ...
- 误删除innodb ibdata数据文件-之恢复
今天在群里看到有人说不熟悉innodb把ibdata(数据文件)和ib_logfile(事务日志)文件误删除了.不知道怎么解决.当时我也不知道怎么办.后来查阅相关资料.终找到解决方法.其实恢复也挺简单 ...
- Java面试——String、StringBuider以及StringBuffer的区别和使用场景
1. String.StringBuider.StringBuffer的区别 String是不可变的对象,因此在每次对String类型进行改变的时候,都会生成一个新的String对象,然后将指针指 ...
- go 本地安装 grpc-go
https://blog.csdn.net/code_segment/article/details/77461590 https://github.com/grpc/grpc-go git clon ...