The 2018 ACM-ICPC Chinese Collegiate Programming Contest 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
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <utility>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <cstdlib>
#include <cmath>
typedef long long ll;
#define lowbit(x) (x&(-x))
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
using namespace std;
#define pi acos(-1)
const int N=;
const int inf=0x3f3f3f3f;
int r[N],f[N][N][N];
int t,n,q;
int id[N];
void solve(int n){
for(int k=;k<=n;k++){
int kk=id[k];//实际顺序
for(int i=;i<=n;i++){
for(int j=;j<=n;j++){
f[k][i][j]=min(f[k-][i][j],f[k-][i][kk]+f[k-][kk][j]);
}
}
}
}
bool cmp(int i,int j){
return r[i]<r[j];
}
int main()
{
scanf("%d",&t);
int i;
for(i=;i<=t;i++){
scanf("%d%d",&n,&q);
for(int j=;j<=n;j++){
id[j]=j;
scanf("%d",&r[j]);
}
memset(f,inf,sizeof(f));
for(int k1=;k1<=n;k1++){
for(int k2=;k2<=n;k2++){
scanf("%d",&f[][k1][k2]);
}
}
sort(id+,id+n+,cmp);//按照r[]从小到大排序,为了solve()
sort(r+,r+n+);//为了找符合条件的k4
solve(n);
printf("Case #%d:\n",i);
int u,v,w;
for(int k3=;k3<=q;k3++){
scanf("%d%d%d",&u,&v,&w);
int k4;
for(k4=;k4<=n;k4++){
if(r[k4]>w){
break;
}
}
printf("%d\n",f[k4-][u][v]);
}
}
return ;
}
The 2018 ACM-ICPC Chinese Collegiate Programming Contest Moving On的更多相关文章
- ACM ICPC, JUST Collegiate Programming Contest (2018) Solution
A:Zero Array 题意:两种操作, 1 p v 将第p个位置的值改成v 2 查询最少的操作数使得所有数都变为0 操作为可以从原序列中选一个非0的数使得所有非0的数减去它,并且所有数不能 ...
- ACM ICPC, Amman Collegiate Programming Contest (2018) Solution
Solution A:Careful Thief 题意:给出n个区间,每个区间的每个位置的权值都是v,然后找长度为k的区间,使得这个区间的所有位置的权值加起来最大,输出最大权值, 所有区间不重叠 思路 ...
- ICPC — International Collegiate Programming Contest Asia Regional Contest, Yokohama, 2018–12–09 题解
目录 注意!!此题解存在大量假算法,请各位巨佬明辨! Problem A Digits Are Not Just Characters 题面 题意 思路 代码 Problem B Arithmetic ...
- 计蒜客 The 2018 ACM-ICPC Chinese Collegiate Programming Contest Rolling The Polygon
include <iostream> #include <cstdio> #include <cstring> #include <string> #i ...
- The 2018 ACM-ICPC Chinese Collegiate Programming Contest Take Your Seat
/* 证明过程如下 :第一种情况:按1到n的顺序上飞机,1会随意选一个,剩下的上去时若与自己序号相同的座位空就坐下去,若被占了就也会随意选一个.求最后一个人坐在应坐位置的概率 */ #include ...
- The 2018 ACM-ICPC Chinese Collegiate Programming Contest Fight Against Monsters
#include <iostream> #include <cstdio> #include <cstring> #include <string> # ...
- The 2018 ACM-ICPC Chinese Collegiate Programming Contest Caesar Cipher
#include <iostream> #include <cstdio> #include <cstring> #include <string> # ...
- The 2018 ACM-ICPC Chinese Collegiate Programming Contest Maximum Element In A Stack
//利用二维数组模拟 #include <iostream> #include <cstdio> #include <cstring> #include <s ...
- ACM International Collegiate Programming Contest, Tishreen Collegiate Programming Contest (2018) Syria, Lattakia, Tishreen University, April, 30, 2018
ACM International Collegiate Programming Contest, Tishreen Collegiate Programming Contest (2018) Syr ...
随机推荐
- autofac 注入生命周期
创建实例方法 1.InstancePerDependency 对每一个依赖或每一次调用创建一个新的唯一的实例.这也是默认的创建实例的方式. 官方文档解释:Configure the component ...
- nodejs 实践:express 最佳实践 (一) 项目结构
express 最佳实践 (一) 第二篇: express 最佳实践(二):中间件 最近,一直在使用 nodejs 做项目,对 nodejs 开发可以说深有体会. 先说说 nodejs 在业务中的脚色 ...
- ES6 Interator
Interator "集合"数据的结构主要有 Array .Object. Set and Map ,任何数据结构只要部署 Iterator 接口,就可完成遍历操作 遍历过程: 创 ...
- CF1157D N Problems During K Days
思路: 在1, 2, 3, ... , k的基础上贪心构造. 实现: #include <bits/stdc++.h> using namespace std; typedef long ...
- 1169 传纸条 2008年NOIP全国联赛提高组 个人博客:attack.cf
1169 传纸条 2008年NOIP全国联赛提高组 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 题目描述 Description 小渊和小轩 ...
- vuejs 学习旅程之 vue-resource
如上图,所有的数据是从php获取过来的.所以就引出了vuejs 与php通信之说.百度了一下需要使用到一个vue插件 就是今天的主题 vuejs 学习旅程之 vue-resource vue-reso ...
- ptxas fatal : Unresolved extern function Error 255
This question already has an answer here: External calls are not supported - CUDA 1 answer I am tryi ...
- Jenkins任务失败,发送邮件通知
1.进入系统管理->系统设置,然后进行下面设置: 2.配置管理员邮件账号,需要和后面的邮件发送者一致.否则可能会发送不成功 3.配置基础的邮件发送的配置 4.配置邮件扩展配置--用来自定义邮件格 ...
- Linux:linux下建ftp用户,并限制用户访问路径
安装:ftp安装部分,操作步骤如下: 可以使用yum命令直接安装ftp # yum install vsftpd ftp服务的开启与关闭命令: 开启:# service vsftpd start 关闭 ...
- 关于纠正《Hive权威指南》中的结论~“hive在使用set自定义变量时,hivevar命名空间是可选的”~的论证
背景: 根据<Hive权威指南>上讲,在hive-0.8.0以后可以使用--define key=value命令定义用户自定义的变量以便在Hive脚本中引用.当用户使用这个功能时,Hive ...