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 ...
随机推荐
- Ngnix技术研究系列1-通过应用场景看Nginx的反向代理
随着我们业务规模的不断增长,整个系统规模由两年前的几十台服务器,井喷到现在2个数据中心,接近400台服务器,上百个WebApi站点,上百个域名. 这么多的WebApi站点这么多的域名,管理和维护成本很 ...
- activemq的安装与使用
一.activemq的安装 环境:CentOS 6.JDK8 1. 确保系统已安装了可用的jdk版本2. 从网上下载 Linux 版的 ActiveMQ( apache-activemq-5.11.1 ...
- 在CentOS7上通过RPM安装实现LAMP+phpMyAdmin过程全记录
在CentOS7上通过RPM安装实现LAMP+phpMyAdmin过程全记录 时间:2017年9月20日 一.软件环境: IP:192.168.1.71 Hostname:centos73-2.sur ...
- 对Java Web项目中路径的理解
第一个:文件分隔符 坑比Window.window分隔符 用\;unix采用/.于是用File.separator来跨平台 请注意:这是文件路径.在File f = new File(“c:\\hah ...
- UpdatePanel控件的使用和局部刷新
http://www.cnblogs.com/baiefjg/archive/2009/06/14/1502813.html
- python使用装饰器@函数式化django开发
django是一个python web开发的框架.作为一个框架MVC的架构已经实现起来了.但是编码的时候你经常要进行进一步的抽象. AOP是一种称为面向切面的开发思想,意思是将部分功能代码在运行时动态 ...
- 实现LAMP
实现LAMP 1.LAMP工作原理 LAMP是一个强大的Web应用程序平台,其中L是指linux系统:A是指apache也就是http;M一般是mysql/mariadb数据库;P一般是php, pe ...
- IOS应用FFMPEG库
1.引用资源 build-ffmpeg ffmpeg库生成 -sh开源地址: https://gist.github.com/m1entus/6983547 iFrameExtractor ffmp ...
- Django REST FrameWork中文教程2:请求和响应
从这一点开始,我们将真正开始覆盖REST框架的核心.我们来介绍几个基本的构建块. 请求对象REST框架引入了Request扩展常规的对象HttpRequest,并提供更灵活的请求解析.Request对 ...
- 面试题:使用LinkedList来模拟一个堆栈或者队列数据结构
请使用LinkedList来模拟一个堆栈或者队列数据结构. 堆栈:先进后出 First In Last Out (FILO) 队列:先进先出 First In First Out (FIFO) 我 ...