Skip to content

Commit c2c23f7

Browse files
committed
提交西邮导游系统
1 parent 793cec1 commit c2c23f7

File tree

8 files changed

+1303
-0
lines changed

8 files changed

+1303
-0
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
1 114 486 2 45
2+
2 114 441 1 45 3 39 4 71
3+
3 153 441 2 39
4+
4 114 370 2 71 5 38
5+
5 76 370 4 38 6 56
6+
6 76 314 5 56 7 13 9 73
7+
7 63 314 6 13
8+
8 63 241 9 13
9+
9 76 241 6 73 8 13 10 26 68 13
10+
10 76 215 9 26 11 70
11+
11 146 215 10 70 12 36
12+
12 172 241 11 36 13 43
13+
13 211 222 64 58 34 32 12 43
14+
14 211 109 64 55 15 55
15+
15 266 109 16 45 19 56 14 55
16+
16 311 109 17 61 20 56 15 45
17+
17 372 109 16 61 21 56 26 44
18+
18 224 53 19 42
19+
19 266 53 18 42 20 45 15 56
20+
20 311 53 16 56 19 45 21 61
21+
21 372 53 17 56 20 61 22 37
22+
22 409 53 21 37 23 36
23+
23 445 53 22 36 24 32
24+
24 445 85 23 32 25 91 27 24
25+
25 536 85 24 91
26+
26 416 109 17 44 27 29 28 19
27+
27 445 109 24 24 26 29 29 19
28+
28 416 128 33 47 26 19 29 29
29+
29 445 128 27 19 28 29 30 55
30+
30 500 128 29 55 31 47
31+
31 500 175 32 28 38 47 30 47
32+
32 528 175 31 28
33+
33 416 175 67 50 36 47 28 47
34+
34 243 222 35 65 40 106 13 32
35+
35 308 222 34 65 66 32 36 108 41 93
36+
36 416 222 33 47 35 108 37 67 43 93
37+
37 483 222 36 67 38 17 44 62
38+
38 500 222 37 17 39 25 31 47
39+
39 525 222 38 25
40+
40 205 321 34 106 53 128
41+
41 308 315 48 46 35 93 42 49
42+
42 357 315 49 27 41 49 43 59
43+
43 416 315 36 93 42 59 45 26
44+
44 458 279 37 62 45 39
45+
45 442 315 43 26 44 39 46 30
46+
46 428 342 49 71 45 30 47 21
47+
47 419 361 50 62 52 27 46 21
48+
48 308 361 50 49 41 46
49+
49 357 342 50 19 42 27 46 71
50+
50 357 361 48 49 49 19 51 25 47 62
51+
51 357 386 50 25 52 51 54 44
52+
52 408 386 51 51 55 48 56 93 47 27
53+
53 267 433 40 128 57 67
54+
54 357 430 51 44 55 31 57 34
55+
55 388 430 52 48 54 31 58 36
56+
56 492 428 52 93 63 71
57+
57 331 453 53 67 54 34 59 38
58+
58 402 464 55 36 59 46 62 69
59+
59 358 480 57 38 58 46 60 27
60+
60 358 507 59 27 61 67
61+
61 291 507 60 67
62+
62 447 517 58 69 63 80
63+
63 523 492 56 71 62 80
64+
64 211 164 65 34 13 58 14 55
65+
65 245 164 64 34
66+
66 308 190 35 32
67+
67 366 175 33 50
68+
68 89 241 9 13
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
����¥���������� 61 ��һ��
2+
���������� 65 �ö�������
3+
������ѧ¥ 5 ������ѧ¥��������ľ��
4+
�������� 12 ���ָ��˺ü�����
5+
�������� 3 �����ܺ���Ĵ���
6+
���� 66 ����
7+
ҽԺ������ 39 ���ñȶ����ã�ҽԺҲͦ�ã��ܱ��������Dz��õ�����
8+
һ��ʵ��¥ 47 ʵ��¥
9+
��ʦ��Ԣ 10 ��֪��������Щ��ʦס��������
10+
ͼ��� 42 �ţ�ȥ������
11+
����10-16����¥ 15 ����¥�ö���
12+
���˺� 41 �������¾ۼ���
13+
�������� 8 ���ö���
14+
���� 25 ���Ҳ���⣡
15+
�������� 60 �붫�����ű��ĸ����أ�
16+
������ 53 �������¾ۼ���
17+
������ѧ¥ 52 �����Ľ�ѧ¥����
18+
������ 67 ������
19+
�������� 33 �������ٳ�����ͼ�汾�Ͼɺٺ�
20+
����ѧ������ 7 ���ǵ��������������
21+
��ʳ�㳡 32 ����Ҳ�ȶ�����
22+
������Ȫ 54 �׳�ˮ����ӣ�
23+
����ʳ�� 68 ��������ʳ��ζ����������ã����أ�
24+
�������� 22 �������ȥ���У�
25+
����Է 26 ���˱ȶ�����
26+
��ѧ������� 48 ��ѧ���������
27+
����ʵ��¥ 45 ʵ��¥
28+
�������� 11 ��������
29+
����ʵ��¥ 44 ʵ��¥
30+
����1-6����¥ 24 7-9�أ�
31+
���������� 1 ������������������
21 KB
Loading
445 KB
Loading
Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
package org.geekgao.guide;
2+
3+
import java.util.HashSet;
4+
import java.util.Iterator;
5+
import java.util.LinkedList;
6+
import java.util.List;
7+
import java.util.Map;
8+
import java.util.Queue;
9+
import java.util.Set;
10+
import java.util.Stack;
11+
12+
13+
/**
14+
*
15+
* @author geekgao
16+
* 提供静态的算法方法
17+
*
18+
*/
19+
20+
public class GuideAlgorithm {
21+
22+
/**
23+
*
24+
* @param start 起始点序号
25+
* @param end 结束点序号
26+
* @param count 点的个数
27+
* @param map 图
28+
* @return
29+
*/
30+
public static Integer[] Dijkstra(int start,int end,int count,Map<Integer,Vertex> map) {
31+
if (start == end) {
32+
return null;
33+
}
34+
35+
class LengthAndRoad{
36+
int length;
37+
List<Integer> road = new LinkedList<Integer>();
38+
}
39+
LengthAndRoad[] temp= new LengthAndRoad[count + 1];//算法中临时用到的那个数组,数组下标对应节点序号
40+
Set<Integer> alreadyFind = new HashSet<Integer>();//已经找到最短路径的那些点的集合
41+
42+
// ===============================================
43+
// 初始化这个数组
44+
Vertex tmpVex = map.get(start);
45+
Set<Integer> point = tmpVex.pointNum.keySet();//这个起始点指向的那些点的序号
46+
for (Integer i:point) {
47+
temp[i] = new LengthAndRoad();
48+
temp[i].length = tmpVex.pointNum.get(i);
49+
temp[i].road = new LinkedList<Integer>();
50+
temp[i].road.add(start);
51+
temp[i].road.add(i);
52+
}
53+
alreadyFind.add(start);
54+
// ===============================================
55+
int currentStart = 0;//每次循环时起始点的序号,循环进去第一步就是选择这个点(路径长度最短的那个点)
56+
int MAX = 2147483647;
57+
for (int k = 1;k <= count;k++) {
58+
long endTime = System.currentTimeMillis();
59+
60+
int minLength = MAX;
61+
int n = -1;//下面这个temp数组计数
62+
for (LengthAndRoad l:temp) {
63+
n++;
64+
if (l == null || alreadyFind.contains(n)) {
65+
continue;
66+
}
67+
if (minLength > l.length) {
68+
minLength = l.length;
69+
currentStart = n;
70+
}
71+
}
72+
if (currentStart == end) {
73+
break;
74+
}
75+
alreadyFind.add(currentStart);
76+
77+
Vertex currentVex = map.get(currentStart);//当前起始点
78+
List<Integer> currentStartRoad = new LinkedList<Integer>(temp[currentStart].road);//当前路径(把起始点路径复制过来)
79+
80+
Set<Integer> currentPoint = currentVex.pointNum.keySet();//获得当前点指向哪些点
81+
for (Integer i:currentPoint) {
82+
if (alreadyFind.contains(i)) {
83+
continue;
84+
}
85+
if ((temp[i] == null) || (temp[currentStart].length + currentVex.pointNum.get(i) < temp[i].length)) {
86+
LengthAndRoad newRoad = new LengthAndRoad();
87+
newRoad.length = temp[currentStart].length + currentVex.pointNum.get(i);
88+
newRoad.road = new LinkedList<Integer>(currentStartRoad);
89+
newRoad.road.add(i);
90+
temp[i] = newRoad;
91+
}
92+
}
93+
}
94+
95+
if (currentStart != end) {
96+
return null;
97+
}
98+
99+
Integer[] result = new Integer[temp[currentStart].road.size()];
100+
int n = 0;
101+
for (Integer i:temp[currentStart].road) {
102+
result[n++] = i;
103+
}
104+
return result;
105+
}
106+
107+
public static Integer[] Bfs(int startNum, Map<Integer, Vertex> map,
108+
Map<String, String> view, Map<Integer, String> viewNumNameMap) {
109+
110+
List<Integer> resultList = new LinkedList<Integer>();
111+
Queue<Integer> q = new LinkedList<Integer>();
112+
113+
Set<Integer> alreadyFind = new HashSet<Integer>();//存储已经访问过的点
114+
q.offer(startNum);//放入起始点
115+
alreadyFind.add(startNum);
116+
while (!q.isEmpty()) {
117+
Integer num = q.poll();
118+
if (viewNumNameMap.containsKey(num)) {
119+
resultList.add(num);
120+
}
121+
Set<Integer> pointNum = map.get(num).pointNum.keySet();
122+
for (Integer i:pointNum) {
123+
if (!alreadyFind.contains(i)) {
124+
q.offer(i);
125+
alreadyFind.add(i);
126+
}
127+
}
128+
}
129+
130+
Integer[] result = new Integer[resultList.size()];
131+
for (int i = 0;i < resultList.size();i++) {
132+
result[i] = resultList.get(i);
133+
}
134+
135+
return result;
136+
}
137+
138+
public static Integer[] Dfs(int startNum, Map<Integer, Vertex> map,
139+
Map<String, String> view, Map<Integer, String> viewNumNameMap) {
140+
141+
List<Integer> resultList = new LinkedList<Integer>();//算法存储最终结果的链表
142+
Stack<Integer> s = new Stack<Integer>();//算法中用到的栈
143+
Set<Integer> alreadyFind = new HashSet<Integer>();//存储已经访问过的点
144+
145+
s.push(startNum);
146+
alreadyFind.add(startNum);
147+
while (!s.isEmpty()) {
148+
int num = s.pop();
149+
if (viewNumNameMap.containsKey(num)) {
150+
resultList.add(num);
151+
}
152+
Map<Integer,Integer> pointNum = map.get(num).pointNum;
153+
for (Iterator<Integer> it = pointNum.keySet().iterator();it.hasNext();) {
154+
int nextNum = it.next();
155+
if (!alreadyFind.contains(nextNum)) {
156+
s.push(nextNum);
157+
alreadyFind.add(nextNum);
158+
}
159+
}
160+
}
161+
Integer[] result = new Integer[resultList.size()];
162+
for (int i = 0;i < resultList.size();i++) {
163+
result[i] = resultList.get(i);
164+
}
165+
166+
return result;
167+
}
168+
169+
}

0 commit comments

Comments
 (0)