Geodetic 集合
来源:互联网 发布:支付宝钱包软件下载 编辑:程序博客网 时间:2024/06/05 14:17
P1212 Geodetic 集合
2017年6月11日
先用Floyd算法算出任意两点之间的距离;
对于要求的任意两个点v, u,枚举所有点(记作 i)如果满足:
Edge[x][i] + Edge[i][y] == Edge[x][y];//Edge表示任意两个点的最短距离
则输出I点。
#include <iostream>#include <cstdio>#include <string>#include <algorithm>#include <cstdlib>#include <cmath>#include <cstring>using namespace std;//100%的数据,n<=40 k<=2000int N, M, K;/*第一行两个整数n,m,分别表示图G的顶点数和边数(顶点编号1-n)下接m行,每行两个整数a,b表示顶点a和b之间有一条无向边。第m+2行有一个整数k,表示给定的点对数。下接k行,每行两个整数v,u。*/int Edge[50][50];void Putin(){ memset(Edge, 10, sizeof(Edge)); cin >> N >> M; int a, b; for(int i = 1; i <= M; i++){ cin >> a >> b; Edge[a][b] = Edge[b][a] = 1; } cin >> K;}void Floyd(){ for(int k = 1; k <= N; k++) for(int i = 1; i <= N; i++) for(int j = 1; j <= N; j++) Edge[i][j] = min(Edge[i][j], (Edge[i][k] + Edge[k][j]));}inline void CalPrt(int x, int y){ for(int i = 1; i <= N; i++){ if(i == x || i == y){ cout << i << ' '; continue; } if(Edge[x][i] + Edge[i][y] == Edge[x][y]) cout << i << ' '; } cout << endl;}int main(){ Putin(); Floyd(); for(int i = 1; i <= K; i++){ int v, u; cin >> v >> u; CalPrt(v, u); } return 0;}
阅读全文
0 0
- Geodetic 集合
- ROI_PAC processing for Modern Geodetic Methods
- POJ 1612 The Geodetic Set Problem (Floyd)
- 如何创建EPSG Geodetic Parameter Dataset for Postgresql 8
- gamit--Geodetic height unreasonable: check p- and l-files
- The Geodetic Set Problem - POJ 1612 Floyd求最短路径所有点集
- 集合
- 集合
- 集合
- 集合
- 集合
- 集合
- 集合
- 集合
- 集合
- 集合
- 集合
- 集合
- maven工程如果选错了module里的war,jar就删删了工程重新做,不然会出一下奇怪的错误
- Unity编译时找不到AndroidSDK的问题:Unable to list target platforms
- hibernate中的session中的方法(网页资料整理)
- C++ 21 —— 异常
- Springboot中redis
- Geodetic 集合
- jQuery.cookie.js使用方法总结
- redis 集群
- 使用Spring MVC创建REST API
- 一个简单的定时任务
- Iterator_traits
- s3c2440 watchdog驱动
- leetcode No72. Edit Distance
- 优秀产品经理的核心技能