宁夏邀请赛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 题意: 根据已给出的式子,进行排序,然后输出排完序后原先的下表. 题解:用结构体保存,在用结构体 ...
随机推荐
- Python函数(1)
一.Python函数介绍 函数时组织好的,可重复的,用来实现单一,或相关联功能的代码段. 函数的使用原则时先定义,后调用:事先准备工具的过程即函数的定义,遇到应用场景拿来当工具用即函数的调用. 函数的 ...
- Yesterday is history, tomorrow is a mystery, but today is a gift.
Yesterday is history, tomorrow is a mystery, but today is a gift.昨天已成历史,明天太过神秘,而今天是一份礼物.
- (转)两张Firefox OS 系统截图
锁屏图 锁屏就是一个向上的小火箭. 桌面 桌面又是另一种风格. 注意 以上为Android系统下运行b2g. 原文地址,TZone
- Mat转化为IplImage类型的方法
Mat image_mat; IplImage imgTmp = image_mat; IplImage *img = cvCloneImage(&imgTmp);
- Azure 本月最新活动,速度Mark!
很多时候,为了知晓 Azure 相关活动的信息,需要到处查阅.问朋友同事,这样既麻烦又易造成延误.为方便广大粉丝,我们推出每月活动合集,帮您第一时间了解 Azure 最新活动,还等什么,一起来看吧! ...
- c#Winform程序调用app.config文件配置数据库连接字符串
你新建winform项目的时候,会有一个app.config的配置文件,写在里面的<connectionStrings name=" " connectionString= ...
- xampp中mysql重置root密码
1. 停止mysql:用图形化工具或者在cmd命令下输入net stop mysql,在c盘根目录下输入 2. 打开cmd,切换目录到 /xampp/mysql/bin, 运行 mysqld ...
- CMAKE 安装
下载 解压 https://cmake.org/download/ https://cmake.org/files/v3.7/cmake-3.7.1.tar.gz yum install gcc - ...
- webpack踩坑
1.当你用webpack2实现css文件单独成一个文件的时候: 可能遇到这种错误Error: Breaking change: extract now only takes a single argu ...
- 为什么CRM Opportunity的删除会触发一个通向BW系统的RFC
今天工作时我发现,我在SE38里用函数CRM_ORDER_DELETE删除一个Opportunity,居然弹出下图这个SAP Logon的屏幕,要连接BR1.这是什么鬼?! 查了一下,BR1是BW系统 ...