WuKong
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 6 |
|
Sample Output
3 Hint: 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<bits/stdc++.h>
#define INF 0x3f3f3f3f
using namespace std;
int mapn[][];
int dp[][];
int n,m;
int Ts,Te,Ws,We;
int u,v,val;
void floyd(){
for(int u=;u<=n;u++){
for(int i=;i<=n;i++){
for(int j=;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=;i<=n;i++){
for(int j=;j<=n;j++){
if(i==j) mapn[i][j]=;
else mapn[i][j]=INF;
dp[i][j]=;
}
}
}
int main(){
// freopen("in.txt","r",stdin);
while(scanf("%d%d",&n,&m)!=EOF&&(n+m)){
init();
for(int i=;i<m;i++){
scanf("%d%d%d",&u,&v,&val);
//cout<<u<<" "<<v<<" "<<val<<endl;
if(mapn[u][v]>val){//重边
mapn[u][v]=mapn[v][u]=val;
dp[u][v]=dp[v][u]=;//初始化相同的城市
}
}
// for(int i=1;i<=n;i++){
// for(int j=1;j<=n;j++){
// cout<<mapn[i][j]<<" ";
// }
// cout<<endl;
// }
scanf("%d%d%d%d",&Ts,&Te,&Ws,&We);
floyd();
int res=-;
// for(int i=1;i<=n;i++){
// for(int j=1;j<=n;j++){
// cout<<mapn[i][j]<<" ";
// }
// cout<<endl;
// }
for(int i=;i<=n;i++){
for(int j=;j<=n;j++){
if(dp[i][j]>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<<res<<endl;
}
}
}
printf("%d\n",res+);
}
return ;
}
WuKong的更多相关文章
- wukong搜索引擎源码解读
转自:https://ayende.com/blog/171745/code-reading-wukong-full-text-search-engine I like reading code, a ...
- wukong.go
package wukong import ( _ "github.com/boltdb/bolt" _ "github.com/cznic/kv&quo ...
- hihoCoder #1870 : Jin Yong’s Wukong Ranking List-闭包传递(递归) (ACM-ICPC Asia Beijing Regional Contest 2018 Reproduction A) 2018 ICPC 北京区域赛现场赛A
P1 : Jin Yong’s Wukong Ranking List Time Limit:1000ms Case Time Limit:1000ms Memory Limit:512MB Desc ...
- wukong引擎源码分析之索引——part 2 持久化 直接set(key,docID数组)在kv存储里
前面说过,接收indexerRequest的代码在index_worker.go里: func (engine *Engine) indexerAddDocumentWorker(shard int) ...
- HDU - 2833 - WuKong
先上题目: WuKong Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tota ...
- 引入Wukong让你的系统瞬间具备IOC能力
[Github源码] 本文重点要说的是如何通过引入Wukong第三方包让自己的系统能够拥有IOC容器能力,但在具体讲解步骤之前,还是想先简单的介绍一下什么是IOC以及它存在的意义:同时也就能清楚Wuk ...
- 「日常训练」Jin Yong’s Wukong Ranking List(HihoCoder-1870)
题意与分析 2018ICPC北京站A题. 题意是这样的,给定若干人的武力值大小(A B的意思是A比B厉害),问到第几行会出现矛盾. 这题不能出现思维定势,看到矛盾就是矛盾并查集--A>B.A&g ...
- wukong引擎源码分析之索引——part 1 倒排列表本质是有序数组存储
searcher.IndexDocument(0, types.DocumentIndexData{Content: "此次百度收购将成中国互联网最大并购"}) engine.go ...
- wukong引擎源码分析之搜索——docid有序的数组里二分归并求交集,如果用跳表的话,在插入索引时会更快
searcher.Search(types.SearchRequest{Text: "百度中国"}) // 查找满足搜索条件的文档,此函数线程安全 func (engine *En ...
随机推荐
- Java钉钉开发_02_免登授权(身份验证)(附源码)
源码已上传GitHub: https://github.com/shirayner/DingTalk_Demo 一.本节要点 1.免登授权的流程 (1)签名校验 (2)获取code,并传到后台 (3) ...
- 每周分享之 二 http协议(3)
本次分享http协议,共分为三部分,这是第三部分,主要讲解一个完整的http请求都经过哪些步骤,当我们在地址栏中输入网址,到返回页面都经历了什么 1.输入网址 当我们在浏览器中输入网址的时候,浏览器就 ...
- JavaWeb(一)Servlet中的ServletConfig与ServletContext
前言 前面我介绍了一下什么是servlet,它的生命周期,执行过程和它的原理.这里我们做一个简单的回顾! 什么是Servlet? servlet 是运行在 Web 服务器中的小型 Java 程序(即: ...
- MySQL之多表操作
前言:之前已经针对数据库的单表查询进行了详细的介绍:MySQL之增删改查,然而实际开发中业务逻辑较为复杂,需要对多张表进行操作,现在对多表操作进行介绍. 前提:为方便后面的操作,我们首先创建一个数据库 ...
- python对列表的联想
python的列表与字典,已经接触无数次了.但是很多用法都记不住,个人觉得归根原因都是只是学了知识点而少用,也少思考.在此试图用宫殿记忆法对它们的用法做个简单的梳理. 首先,说说列表的删除,删除有三种 ...
- 从 JavaScript 到 TypeScript 系列
随着应用的庞大,项目中 JavaScript 的代码也会越来越臃肿,这时候许多 JavaScript 的语言弊端就会愈发明显,而 TypeScript 的出现,就是着力于解决 JavaScript 语 ...
- HDU2089 暴力打表
62的判断就是倒过来没有26 hdu2089 #include<cstdio> #include<cstdlib> #include<iostream> #incl ...
- Jquery滚动到页面底部自动Ajax加载图文列表,类似图片懒加载效果,带加载效果
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- wpf值转换器IValueConverter例子
转载:http://blog.163.com/wangzhenguo2005@126/blog/static/37140526201085113430862/ 值转换器可以把一种类型转换成另一种类型. ...
- 【学习】如何用jQuery获取iframe中的元素
(我的博客网站中的原文:http://www.xiaoxianworld.com/archives/292,欢迎遇到的小伙伴常来瞅瞅,给点评论和建议,有错误和不足,也请指出.) 说实在的,以前真的很少 ...