博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
WuKong
阅读量:7094 次
发布时间:2019-06-28

本文共 3691 字,大约阅读时间需要 12 分钟。

WuKong

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 213 Accepted Submission(s): 91
 
Problem Description
Liyuan wanted to rewrite the famous book “Journey to the West” (“Xi You Ji” in Chinese pinyin). In the original book, the Monkey King Sun Wukong was trapped by the Buddha for 500 years, then he was rescued by Tang Monk, and began his journey to the west. Liyuan thought it is too brutal for the monkey, so he changed the story:
One day, Wukong left his home - Mountain of Flower and Fruit, to the Dragon   King’s party, at the same time, Tang Monk left Baima Temple to the Lingyin Temple to deliver a lecture. They are both busy, so they will choose the shortest path. However, there may be several different shortest paths between two places. Now the Buddha wants them to encounter on the road. To increase the possibility of their meeting, the Buddha wants to arrange the two routes to make their common places as many as possible. Of course, the two routines should still be the shortest paths.
Unfortunately, the Buddha is not good at algorithm, so he ask you for help.
 
Input
There are several test cases in the input. The first line of each case contains the number of places N (1 <= N <= 300) and the number of roads M (1 <= M <= N*N), separated by a space. Then M lines follow, each of which contains three integers a b c, indicating there is a road between place a and b, whose length is c. Please note the roads are undirected. The last line contains four integers A B C D, separated by spaces, indicating the start and end points of Wukong, and the start and end points of Tang Monk respectively.
The input are ended with N=M=0, which should not be processed.
 
Output
Output one line for each case, indicating the maximum common points of the two shortest paths.
 
Sample Input
6 61 2 12 3 13 4 14 5 11 5 24 6 31 6 2 40 0
 
Sample Output
3Hint: One possible arrangement is (1-2-3-4-6) for Wukong and (2-3-4) for Tang Monk. The number of common points are 3.
 
 
Source
2009 Multi-University Training Contest 2 - Host by TJU
 
Recommend
gaojie
 
/*题意:给你一个图,然后给出悟空的起始位置,末位置,唐僧的初位置,末位置,然后让你计算一下,在重复最多城市    的最短路的重复城市的数量。    初步思路:dp,dp[i][j]表示从i到j重复的城市数量*/#include
#define INF 0x3f3f3f3fusing namespace std;int mapn[310][310];int dp[310][310];int n,m;int Ts,Te,Ws,We;int u,v,val;void floyd(){ for(int u=1;u<=n;u++){ for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ if(mapn[i][j]>mapn[i][u]+mapn[u][j]){ mapn[i][j]=mapn[i][u]+mapn[u][j]; dp[i][j]=dp[i][u]+dp[u][j]; }else if(mapn[i][j]==mapn[i][u]+mapn[u][j]){ dp[i][j]=max(dp[i][u]+dp[u][j],dp[i][j]); } } } }}void init(){ for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ if(i==j) mapn[i][j]=0; else mapn[i][j]=INF; dp[i][j]=0; } }}int main(){ // freopen("in.txt","r",stdin); while(scanf("%d%d",&n,&m)!=EOF&&(n+m)){ init(); for(int i=0;i
val){
//重边 mapn[u][v]=mapn[v][u]=val; dp[u][v]=dp[v][u]=1;//初始化相同的城市 } } // for(int i=1;i<=n;i++){ // for(int j=1;j<=n;j++){ // cout<
<<" "; // } // cout<
res&&( mapn[Ts][Te]==mapn[Ts][i]+mapn[i][j]+mapn[j][Te] )&&( mapn[Ws][We]==mapn[Ws][i]+mapn[i][j]+mapn[j][We]) ){ res=dp[i][j]; // cout<
<

 

转载于:https://www.cnblogs.com/wuwangchuxin0924/p/6404341.html

你可能感兴趣的文章
前端应用框架(三)
查看>>
多线程的死锁
查看>>
定时任务框架Quartz-(一)Quartz入门与Demo搭建
查看>>
css导航栏
查看>>
洛谷3195(HNOI2008)玩具装箱
查看>>
智能公交报站系统RFID解决方案
查看>>
计算最长英语单词链(单词接龙)
查看>>
vsftp虚拟用户配置
查看>>
oracle11g与oracle10g字符集子集与超集的对应关系表
查看>>
登录注册D
查看>>
deepin-wine-tim 字体发虚
查看>>
windows多线程没那么难
查看>>
ID3决策树算法原理及C++实现(其中代码转自别人的博客)
查看>>
linux之SQL语句简明教程---WHERE
查看>>
霍夫变换(hough transform),从直线到圆再到一般图形
查看>>
程序员技术练级攻略--练成这样,成神仙了!
查看>>
基金净值简介
查看>>
打开myeclipse出现这个错是为什么
查看>>
mongdb使用
查看>>
Hadoop Streaming框架使用(二)
查看>>