宁夏邀请赛F FLOYD
Moving On
Firdaws and Fatinah are living in a country with nn cities, numbered from 11 to nn.Each city has a risk of kidnapping or robbery.
Firdaws's home locates in the city uu, and Fatinah's home locates in the city vv.Now you are asked to find the shortest path from the city uu to the city vv that does not pass through any other city with the risk of kidnapping or robbery higher than ww, a threshold given by Firdaws.
Input Format
The input contains several test cases, and the first line is a positive integer TT indicating the number of test cases which is up to 5050.
For each test case, the first line contains two integers n~(1\le n\le 200)n (1≤n≤200) which is the number of cities, and q~(1\le q\le 2\times 10^4)q (1≤q≤2×104) which is the number of queries that will be given.The second line contains nn integers r_1, r_2, \cdots, r_nr1,r2,⋯,rn indicating the risk of kidnapping or robbery in the city 11 to nn respectively.Each of the following nnlines contains nn integers, the jj-th one in the ii-th line of which, denoted by d_{i,j}di,j, is the distance from the city ii to the city jj.
Each of the following qq lines gives an independent query with three integers u, vu,v and ww, which are described as above.
We guarantee that 1\le r_i \le 10^51≤ri≤105, 1\le d_{i,j}\le 10^5~(i \neq j)1≤di,j≤105 (i≠j), d_{i,i}=0di,i=0 and d_{i,j}=d_{j,i}di,j=dj,i.Besides, each query satisfies 1\le u,v\le n1≤u,v≤n and 1\le w\le 10^51≤w≤105.
Output Format
For each test case, output a line containing Case #x:
at first, where xx is the test case number starting from 11.Each of the following qq lines contains an integer indicating the length of the shortest path of the corresponding query.
样例输入
1
3 6
1 2 3
0 1 3
1 0 1
3 1 0
1 1 1
1 2 1
1 3 1
1 1 2
1 2 2
1 3 2
样例输出
Case #1:
0
1
3
0
1
2
题目来源
The 2018 ACM-ICPC Chinese Collegiate Programming Contest
思路:动态规划f[i][j][k]记录经过前i个城市从j到k的最小风险,再将每个城市的风险进行排序,用于转移与计算。
代码:
#include"bits/stdc++.h"
#define ci(x) scanf("%d",&x)
const int N = 1e6 + ;
using namespace std;
int t,n,q;
struct P
{
int id,r;
};
P a[N];
int f[][][];
bool cmp(P a,P b){
return a.r<b.r;
}
void cal(int m){
for(int i=;i<=m;i++){
int id=a[i].id;
for(int j=;j<=n;j++){
for(int k=;k<=n;k++){
f[i][j][k]=min(f[i-][j][k],f[i-][j][id]+f[i-][id][k]);
}
}
}
}
int main(){
//freopen("data.in","r",stdin);
//freopen("data.out","w",stdout);
scanf("%d",&t);
for(int ii=;ii<=t;ii++){
scanf("%d%d",&n,&q);
for(int i=;i<=n;i++) ci(a[i].r),a[i].id=i;
memset(f,inf,sizeof(f));
for(int i=;i<=n;i++)
for(int j=;j<=n;j++) ci(f[][i][j]);
sort(a+,a+n+,cmp);
cal(n);
printf("Case #%d:\n",ii);
int u,v,w;
for(int i=;i<q;i++){
ci(u),ci(v),ci(w);
int k;
for(k=;k<=n;k++) if(a[k].r>w) break;
printf("%d\n",f[k-][u][v]);
}
}
return ;
}
宁夏邀请赛F FLOYD的更多相关文章
- 2018宁夏邀请赛 L Continuous Intervals(单调栈+线段树)
2018宁夏邀请赛 L Continuous Intervals(单调栈+线段树) 传送门:https://nanti.jisuanke.com/t/41296 题意: 给一个数列A 问在数列A中有多 ...
- 2018acm-icpc宁夏邀请赛后记
由于要准备期末考试的缘故,时隔一个月之后我才想起来还有一场比赛没有总结. 大概是出去过的最远的地方了,宁夏理工学院离杭州有两千多千米. 不得不说感到了主办方满满的诚意,虽然是第一次办比赛,但是第一天组 ...
- “2018宁夏邀请赛 ” 兼 “The 2019 Asia Yinchuan First Round Online Programming”
------------7题弟弟,被各位半小时13题的大佬打惨了(滑稽)---------- 签到题就不写了. F :Moving On (1247ms) 题意:给定大小为N的带 ...
- 2018宁夏邀请赛网赛 I. Reversion Count(java练习题)
题目链接 :https://nanti.jisuanke.com/t/26217 Description: There is a positive integer X, X's reversion c ...
- 2018宁夏邀请赛G(DFS,动态规划【VECTOR<PAIR>】)
//代码跑的很慢四秒会超时,结尾附两秒代码(标程) #include<bits/stdc++.h>using namespace std;typedef long long ll;cons ...
- 【郑轻邀请赛 F】 Tmk吃汤饭
[题目链接]:https://acm.zzuli.edu.cn/zzuliacm/problem.php?id=2132 [题意] [题解] 很容易想到用队列来模拟; 这个队列维护的是正在煮的4个人煮 ...
- 2019icpc南昌邀请赛F(线段树)
题目链接:https://nanti.jisuanke.com/t/40258 题意:给长为n的数组a,有m次操作,包括单点修改和查询F(l,r),其值为所有f(i,j)的异或和,l<=i< ...
- [ICPC 2018 宁夏邀请赛] A-Maximum Element In A Stack(思维)
>传送门< 前言 辣鸡网络赛,虽然我是个菜鸡,然而好几个队伍十几分钟就AK???我心态那会彻底崩了,后来群里炸了,话题直接上知乎热搜,都是2018ICPC宁夏网络赛原题,这怎么玩,拼手速? ...
- hdu - 6281,2018CCPC湖南全国邀请赛F题,快排
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6281 题意: 根据已给出的式子,进行排序,然后输出排完序后原先的下表. 题解:用结构体保存,在用结构体 ...
随机推荐
- Hibernate课程 初探一对多映射5-2 Eclipse添加数据库连接
1 Eclipse新建java项目 2 Windows ==> show view == >other ==>Data source Explorer 3 左侧视图 database ...
- Axis Java调C# Webservice
这是一个痛苦的过程,如果java对java的webservice可以说很方便,很简单,Axis,CXF等一系列框架生成客户端直接传参调用即可,但是异构语言就有点麻烦了,生成的客户端不好使......无 ...
- 笨办法学Python(二十六)
习题 26: 恭喜你,现在可以考试了! 你已经差不多完成这本书的前半部分了,不过后半部分才是更有趣的.你将学到逻辑,并通过条件判断实现有用的功能. 在你继续学习之前,你有一道试题要做.这道试题很难,因 ...
- Simotion应用案例,使用Simotion web server调试,使用Project Generator创建项目,Simosim模拟运行运行项目
Simotion web server simotion项目设计和调试过程中,web server功能越来越常用.例如Project generator生成的FBAxis, winder, print ...
- OpenGL学习 Following the Pipeline
Passing Data to the Vertex Shader Vertex Attributes At the start of the OpenGL pipeline,we use the i ...
- 解决Zend加密的PHP页面出现Incompatible file format的问题
错误如图: 致命错误:不兼容的文件格式可能的原因: 1.文件本身加密的问题,很有可能你用的Zend进行加密了,但是因为版本的问题,很有可能是你的主机上的Zend Optimizer版本太低了.2.文件 ...
- 【CCPC-Wannafly Winter Camp Day4 (Div1) D】欧拉回路(分类讨论)
点此看题面 大致题意: 有一个\(n\)行\(m\)列的网格图,让你给每一条边设置一个通过次数(\(\ge1\)),使其成为欧拉回路,且通过次数总和最小. 初始化 首先,由于通过次数\(\ge1\), ...
- 认识http客户端
最简单的http客户端就是我们的浏览器,浏览器地址输入baidu.com,就会返回响应内容,打开network,都是http请求,第一个就是www.baidu.com的请求,旁边第一个General就 ...
- v-for的深层用法
为了提升循环的性能,我们会给循环加上一个唯一的key值,这个key值一定是唯一的 <div id='root'> <div v-for='(item,index) of list' ...
- Java从入门到放弃——02.常量、变量、数据类型、运算符
本文目标 理解什么是常量,什么是变量 认识八大基本数据类型 了解算数运算符.赋值运算符.关系运算符.逻辑运算符.位运算符.三元运算符 1.什么是常量与变量? 常量是相对静止的量,比如整数:1,2,3 ...