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 ...
随机推荐
- windows下指定端口号起步memcached
双击.exe启动的话,默认启动的端口是11211 ,要指定端口的话加 -p + 端口号,如: E:\tools\memcached-1.4.5-win32>memcached-1.4.5.exe ...
- 关于office转换成pdf组件服务中的DCOM配置问题
在开始->运行 中录入“dcomcnfg” 单击“确定”后弹出“组件服务”窗口 依次选择“组件服务”->“计算机”->“我的电脑”->“DCOM配置” 在“DCOM配置”下找到 ...
- Netty之WebSocket和四种IO介绍
Netty简介 一.什么是netty? 高性能 事件驱动 异步非堵塞 基于NIO的客户端,服务器端编程框架 稳定性和伸缩性 二.Netty的使用场景 高性能领域 多线程并发领域 异步通信领域 ...
- .net framework MVC 下 Hangfire使用,时区,权限
安装 NuGet 上有几个可用的Hangfire 的软件包.如果在ASP.NET应用程序中安装HangFire,并使用Sql Server作为存储器,那么请在Package Manager Conso ...
- postgresql+ C#+ DHTMLX 学习汇总
前台: dhtmlxgrid.显示数据 其格式为: { rows:[ {id:1,data:[1,2,3]} ,{} ]} 如果在postgesql里直接生成这样的串呢?? 这是就今天要做的事. ...
- go语言简单的soap调用方法
package main import ( "bytes" "encoding/xml" "fmt" "io" &quo ...
- IDEA创建maven项目的web.xml头
使用IDEA创建maven项目骨架是webapp时,软件自动创建的web.xml文件是2.3版本的,不能使用el表达式,所以可以手动换成4.0的文件头. <?xml version=" ...
- ThreadLocal的内存泄露
ThreadLocal的目的就是为每一个使用ThreadLocal的线程都提供一个值,让该值和使用它的线程绑定,当然每一个线程都可以独立地改变它绑定的值.如果需要隔离多个线程之间的共享冲突,可以使用T ...
- js进阶之function对象
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding= ...
- COGS 147. [USACO Jan08] 架设电话线
★★☆ 输入文件:phoneline.in 输出文件:phoneline.out 简单对比时间限制:1 s 内存限制:16 MB Farmer John打算将电话线引到自己的农场,但电 ...