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 ...
随机推荐
- angular directive知识
一般来讲 directive名字遵循一下规则: 1.忽略以x-和data-为元素/属性的前缀 2.转化“:”,“-”,“_”命名为驼峰命名 如下所示 <div ng-controller=&qu ...
- Zend Framework 3.0 安装及创建初始化项目教程
前言: 最近开始接触关于PHP的框架的学习,然而PHP的框架少说也有七八种. 百度了一下,有人说ThinkPHP简单暴力的,有人说Laravel高大上的,等等等等,难以抉择. 最终我还是选择先从接触Z ...
- IDEA用maven创建springMVC项目和配置
工具准备:IDEA2016.3 Java jdk 1.8 1.DEA创建项目 新建一个maven project,并且选择webapp原型. 然后点击next 这里的GroupId和Artifac ...
- GitHub使用(四) - 关于分支Branch
1. 什么是分支Branch? 我初步的理解为:GitHub仓库默认有一个master的分支,当我们在master分支开发过程中接到一个新的功能需求,我们就可以新建一个分支同步开发而互不影响,开发完成 ...
- Ubuntu升级出现/boot空间不足解决
经常升级Linux内核,导致更新时警告/boot分区空间不足.这是以为多次升级内核后,导致内核版本太多,清理一下没用的内核文件就行了.命令如下: zht@zht-Ubuntu:~$ dpkg -l ' ...
- 你真的会阅读Java的异常信息吗?
给出如下异常信息: java.lang.RuntimeException: level 2 exception at com.msh.demo.exceptionStack.Test.fun2(Tes ...
- numpy学习整理
今天先整理到这里,剩下的下次再整理 1.改变形状: reshape()返回改变的数组形状,但无法改变源数组形状 resize() 可以改变源数组形状 ravel() 输出类似C数组的列表,和resha ...
- WinForm事件中的Object sender和EventArgs e参数
Windows程序有一个事件机制.用于处理用户事件. 在WinForm中我们经常需要给控件添加事件.例如给一个Button按钮添加一个Click点击事件.给TextBox文本框添加一个KeyPress ...
- 前端基础之JavaScript
什么是JavaScript? JavaScript,也称ECMAScript,是一种基于对象和事件驱动并具有相对安全性并广泛用于客户端网页开发的脚本语言,同时也是一种广泛用于客户端Web开发的脚本语言 ...
- WDA的配置
WDA的配置 SAP的技术总是搞得很复杂,WDA的涉及到配置如下: 1. Internet Communication Manager 确认ICM中提供的HTTP/HTTPS运行正常. Tcode: ...