其他分享
首页 > 其他分享> > 2018-2019 ACM-ICPC, China Multi-Provincial Collegiate Programming Contest

2018-2019 ACM-ICPC, China Multi-Provincial Collegiate Programming Contest

作者:互联网

宁夏邀请赛的题,网络赛出锅之后来补了一下,还蛮有意思。题目地址:https://codeforces.com/gym/102222

A、给你一个栈和一堆pop、push操作,每次操作之后询问栈中的最大值,如果栈为空输出0

输入是给定的一个随机数生成器

每一次有元素进栈就把他与当前最大值比较,更新最大值之后把最大值压入另一个栈,pop时两个栈同时操作,每次输出另一个栈的栈顶即可

(这就是单调栈?)

代码:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int t,n,p,q,m,Case=1;
unsigned int SA,SB,SC;
stack<unsigned int> mx;
ll ans;

unsigned int rng61(){
    SA^=SA<<16;
    SA^=SA>>5;
    SA^=SA<<1;
    unsigned int t=SA;
    SA=SB;
    SB=SC;
    SC^=t^SA;
    return SC;
}

void Push(unsigned int v){
    if(mx.empty()) mx.push(v);
    else mx.push(max(mx.top(),v));
}

void Pop(){
    if(mx.empty()) return;
    mx.pop();
}

void gen(){
    ans=0;
    scanf("%d%d%d%d%u%u%u",&n,&p,&q,&m,&SA,&SB,&SC);
    while(!mx.empty()) mx.pop();
    for(int i=1;i<=n;++i){
        if(rng61()%(p+q)<p)
            Push(rng61()%m+1);
        else
            Pop();
        if(!mx.empty()) ans^=((ll)i*mx.top());
    }
    printf("Case #%d: %lld\n",Case,ans);
}

int main(){
    scanf("%d",&t);
    for(;Case<=t;++Case)
        gen();
    return 0;
}

B、给定一个多边形,一开始p[0]到p[1]这条边在一条直线上,然后不断逆时针旋转多边形使得p[i]到p[i+1]这条边落到直线上

当p[0]到p[1]再次落到直线上时停止旋转

问你多边形内的一个点在这个过程中走了多长

假设每一次旋转的弧度为alpha,画个图就能看出来alpha等于pi减去当前线段与下一条线段的夹角,用余弦定理算夹角就完事

如图:

 

 代码:

#include <bits/stdc++.h>
#define int long long
#define sc(a) scanf("%lld",&a)
#define scc(a,b) scanf("%lld %lld",&a,&b)
#define sccc(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define schar(a) scanf("%c",&a)
#define pr(a) printf("%lld",a)
#define fo(i,a,b) for(int i=a;i<b;++i)
#define re(i,a,b) for(int i=a;i<=b;++i)
#define rfo(i,a,b) for(int i=a;i>b;--i)
#define rre(i,a,b) for(int i=a;i>=b;--i)
#define prn() printf("\n")
#define prs() printf(" ")
#define mkp make_pair
#define pii pair<int,int>
#define pub(a) push_back(a)
#define pob() pop_back()
#define puf(a) push_front(a)
#define pof() pop_front()
#define fst first
#define snd second
#define frt front()
#define bak back()
#define mem0(a) memset(a,0,sizeof(a))
#define memmx(a) memset(a,0x3f3f,sizeof(a))
#define memmn(a) memset(a,-0x3f3f,sizeof(a))
#define debug
#define db double
#define yyes cout<<"YES"<<endl;
#define nno cout<<"NO"<<endl;
using namespace std;
typedef vector<int> vei;
typedef vector<pii> vep;
typedef map<int,int> mpii;
typedef map<char,int> mpci;
typedef map<string,int> mpsi;
typedef deque<int> deqi;
typedef deque<char> deqc;
typedef priority_queue<int> mxpq;
typedef priority_queue<int,vector<int>,greater<int> > mnpq;
typedef priority_queue<pii> mxpqii;
typedef priority_queue<pii,vector<pii>,greater<pii> > mnpqii;
const int maxn=500005;
const int inf=0x3f3f3f3f3f3f3f3f;
const int MOD=100000007;
const db eps=1e-10;
const db pi=3.1415926535;
int qpow(int a,int b){int tmp=a%MOD,ans=1;while(b){if(b&1){ans*=tmp,ans%=MOD;}tmp*=tmp,tmp%=MOD,b>>=1;}return ans;}
int lowbit(int x){return x&-x;}
int max(int a,int b){return a>b?a:b;}
int min(int a,int b){return a<b?a:b;}
int mmax(int a,int b,int c){return max(a,max(b,c));}
int mmin(int a,int b,int c){return min(a,min(b,c));}
void mod(int &a){a+=MOD;a%=MOD;}
bool chk(int now){}
int half(int l,int r){while(l<=r){int m=(l+r)/2;if(chk(m))r=m-1;else l=m+1;}return l;}
int ll(int p){return p<<1;}
int rr(int p){return p<<1|1;}
int mm(int l,int r){return (l+r)/2;}
int lg(int x){if(x==0) return 1;return (int)log2(x)+1;}
bool smleql(db a,db b){if(a<b||fabs(a-b)<=eps)return true;return false;}
db len(db a,db b,db c,db d){return sqrt((a-c)*(a-c)+(b-d)*(b-d));}
bool isp(int x){if(x==1)return false;if(x==2)return true;for(int i=2;i*i<=x;++i)if(x%i==0)return false;return true;}

int t,n,Case=1;
struct point{
    db x,y;
}p[maxn],q;

db len(point a,point b){
    return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
    sc(t);
    for(;Case<=t;++Case){
        db ans=0.0;
        sc(n);
        re(i,0,n-1) scanf("%lf%lf",&p[i].x,&p[i].y);
        p[n]=p[0],p[n+1]=p[1];
        scanf("%lf%lf",&q.x,&q.y);
        re(i,1,n){
            db a=len(p[i-1],p[i]);
            db b=len(p[i],p[i+1]);
            db c=len(p[i-1],p[i+1]);
            db alpha=acos((a*a+b*b-c*c)/(2.0*a*b));
            alpha=pi-alpha;
            ans+=alpha*len(q,p[i]);
        }
        printf("Case #%d: ",Case,ans);
        printf("%.3lf\n",ans);
    }
    return 0;
}

C、给你三个小写字母字符串,第二个字符串是由第一个字符串的每一位加n再对26取余得到的

要求求出n,然后把第三个字符串每一位减n加26再对26取余,输出结果

按照题意搞就行

代码:

#include <bits/stdc++.h>
#define int long long
#define sc(a) scanf("%lld",&a)
#define scc(a,b) scanf("%lld %lld",&a,&b)
#define sccc(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define schar(a) scanf("%c",&a)
#define pr(a) printf("%lld",a)
#define fo(i,a,b) for(int i=a;i<b;++i)
#define re(i,a,b) for(int i=a;i<=b;++i)
#define rfo(i,a,b) for(int i=a;i>b;--i)
#define rre(i,a,b) for(int i=a;i>=b;--i)
#define prn() printf("\n")
#define prs() printf(" ")
#define mkp make_pair
#define pii pair<int,int>
#define pub(a) push_back(a)
#define pob() pop_back()
#define puf(a) push_front(a)
#define pof() pop_front()
#define fst first
#define snd second
#define frt front()
#define bak back()
#define mem0(a) memset(a,0,sizeof(a))
#define memmx(a) memset(a,0x3f3f,sizeof(a))
#define memmn(a) memset(a,-0x3f3f,sizeof(a))
#define debug
#define db double
#define yyes cout<<"YES"<<endl;
#define nno cout<<"NO"<<endl;
using namespace std;
typedef vector<int> vei;
typedef vector<pii> vep;
typedef map<int,int> mpii;
typedef map<char,int> mpci;
typedef map<string,int> mpsi;
typedef deque<int> deqi;
typedef deque<char> deqc;
typedef priority_queue<int> mxpq;
typedef priority_queue<int,vector<int>,greater<int> > mnpq;
typedef priority_queue<pii> mxpqii;
typedef priority_queue<pii,vector<pii>,greater<pii> > mnpqii;
const int maxn=500005;
const int inf=0x3f3f3f3f3f3f3f3f;
const int MOD=100000007;
const db eps=1e-10;
int qpow(int a,int b){int tmp=a%MOD,ans=1;while(b){if(b&1){ans*=tmp,ans%=MOD;}tmp*=tmp,tmp%=MOD,b>>=1;}return ans;}
int lowbit(int x){return x&-x;}
int max(int a,int b){return a>b?a:b;}
int min(int a,int b){return a<b?a:b;}
int mmax(int a,int b,int c){return max(a,max(b,c));}
int mmin(int a,int b,int c){return min(a,min(b,c));}
void mod(int &a){a+=MOD;a%=MOD;}
bool chk(int now){}
int half(int l,int r){while(l<=r){int m=(l+r)/2;if(chk(m))r=m-1;else l=m+1;}return l;}
int ll(int p){return p<<1;}
int rr(int p){return p<<1|1;}
int mm(int l,int r){return (l+r)/2;}
int lg(int x){if(x==0) return 1;return (int)log2(x)+1;}
bool smleql(db a,db b){if(a<b||fabs(a-b)<=eps)return true;return false;}
db len(db a,db b,db c,db d){return sqrt((a-c)*(a-c)+(b-d)*(b-d));}
bool isp(int x){if(x==1)return false;if(x==2)return true;for(int i=2;i*i<=x;++i)if(x%i==0)return false;return true;}

int t,n,m;
string s1,s2,s3;

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
    cin>>t;
    re(jj,1,t){
        cin>>n>>m;
        cin>>s1>>s2>>s3;
        int dif=s2[0]-s1[0];
        fo(i,0,m){
            s3[i]=(s3[i]-'A'-dif+26)%26+'A';
        }
        cout<<"Case #"<<jj<<": "<<s3<<endl;
    }
    return 0;
}

H、n只怪物,你对每只怪物的伤害是1、2、3、4,意味着每一次攻击怪物,你对这只怪物的伤害就会增加1

每攻击一次,所有存活的怪物都会对你造成伤害,现在你要挑选一个合适的攻击顺序,使得自己受到的伤害最小

首先考虑对单只怪物,一定要把它打倒再打下一只才更优,应当尽快减少怪物的数量

考虑经典的贪心策略,假设怪物a排在怪物b前面,那么应当满足下面的条件:

杀死怪物a的时间*(怪物a、b的攻击力)+(杀死怪物a、b的时间)*怪物b的攻击力

小于

杀死怪物b的时间*(怪物a、b的攻击力)+(杀死怪物a、b的时间)*怪物a的攻击力

写个排序函数搞一下完事。

代码:

#include <bits/stdc++.h>
#define int long long
#define sc(a) scanf("%lld",&a)
#define scc(a,b) scanf("%lld %lld",&a,&b)
#define sccc(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define schar(a) scanf("%c",&a)
#define pr(a) printf("%lld",a)
#define fo(i,a,b) for(int i=a;i<b;++i)
#define re(i,a,b) for(int i=a;i<=b;++i)
#define rfo(i,a,b) for(int i=a;i>b;--i)
#define rre(i,a,b) for(int i=a;i>=b;--i)
#define prn() printf("\n")
#define prs() printf(" ")
#define mkp make_pair
#define pii pair<int,int>
#define pub(a) push_back(a)
#define pob() pop_back()
#define puf(a) push_front(a)
#define pof() pop_front()
#define fst first
#define snd second
#define frt front()
#define bak back()
#define mem0(a) memset(a,0,sizeof(a))
#define memmx(a) memset(a,0x3f3f,sizeof(a))
#define memmn(a) memset(a,-0x3f3f,sizeof(a))
#define debug
#define db double
#define yyes cout<<"YES"<<endl;
#define nno cout<<"NO"<<endl;
using namespace std;
typedef vector<int> vei;
typedef vector<pii> vep;
typedef map<int,int> mpii;
typedef map<char,int> mpci;
typedef map<string,int> mpsi;
typedef deque<int> deqi;
typedef deque<char> deqc;
typedef priority_queue<int> mxpq;
typedef priority_queue<int,vector<int>,greater<int> > mnpq;
typedef priority_queue<pii> mxpqii;
typedef priority_queue<pii,vector<pii>,greater<pii> > mnpqii;
const int maxn=500005;
const int inf=0x3f3f3f3f3f3f3f3f;
const int MOD=100000007;
const db eps=1e-10;
int qpow(int a,int b){int tmp=a%MOD,ans=1;while(b){if(b&1){ans*=tmp,ans%=MOD;}tmp*=tmp,tmp%=MOD,b>>=1;}return ans;}
int lowbit(int x){return x&-x;}
int max(int a,int b){return a>b?a:b;}
int min(int a,int b){return a<b?a:b;}
int mmax(int a,int b,int c){return max(a,max(b,c));}
int mmin(int a,int b,int c){return min(a,min(b,c));}
void mod(int &a){a+=MOD;a%=MOD;}
bool chk(int now){}
int half(int l,int r){while(l<=r){int m=(l+r)/2;if(chk(m))r=m-1;else l=m+1;}return l;}
int ll(int p){return p<<1;}
int rr(int p){return p<<1|1;}
int mm(int l,int r){return (l+r)/2;}
int lg(int x){if(x==0) return 1;return (int)log2(x)+1;}
bool smleql(db a,db b){if(a<b||fabs(a-b)<=eps)return true;return false;}
db len(db a,db b,db c,db d){return sqrt((a-c)*(a-c)+(b-d)*(b-d));}
bool isp(int x){if(x==1)return false;if(x==2)return true;for(int i=2;i*i<=x;++i)if(x%i==0)return false;return true;}

int t,n;
int Case=1;
vei v;
struct node{
    int hp,atk;
}o[maxn];

bool cmp(node a,node b){
    int p1=lower_bound(v.begin(),v.end(),a.hp)-v.begin()+1;
    int p2=lower_bound(v.begin(),v.end(),b.hp)-v.begin()+1;
    return a.atk*p1+b.atk*(p1+p2)<b.atk*p2+a.atk*(p1+p2);
}

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
    sc(t);
    re(i,1,10000) v.pub((1+i)*i/2);
    for(;Case<=t;++Case){
        int ans=0,sum=0;
        sc(n);
        re(i,1,n) scc(o[i].hp,o[i].atk),sum+=o[i].atk;
        sort(o+1,o+1+n,cmp);
        re(i,1,n){
            int p=lower_bound(v.begin(),v.end(),o[i].hp)-v.begin()+1;
            ans+=sum*p;
            sum-=o[i].atk;
        }
        printf("Case #%lld: %lld\n",Case,ans);
    }
    return 0;
}

D、题意比较抽象

先说第一小问,n个人上飞机,第i个人本来应该坐在第i个位置

现在第一个人票丢了,他会随机选择一个座位

从第二个人开始,如果他本来的位置上没人,他就会坐本来的位置,否则他也会随机选择一个座位

第一问是问第n个人坐到本来的位置的概率是多少

不妨假设f(x)表示x个人时候的答案

考虑只有一个人的情况:

他必定坐回一号位,概率为1.0,即f(1)=1

考虑只有两个人的情况:

如果第一个人坐了一号位,第二人必坐二号位;如果第一个人坐了二号位,那么第二人必坐一号位,概率为0.5,f(2)=0.5

接下来考虑f(3):

如果第一个人坐了一号位,概率为1.0

如果第一个人坐了二号位,相当于第二个人变成了第一个人,概率为f(2)

如果第一个人坐了三号位,无论如何最后一个人也不会坐回原来的位置,概率为0

所以f(3)=1*1/3+f(2)*1/3+0*1/3=0.5

实际上对于任意的f(x),f(x)=1*1/x+f(2)*1/x+...+f(x-1)*1/x+0*1/x=0.5

这意味着第一个人坐到哪个位置上了,那么答案就等于f(从那个位置开始的人数)

第二问是说上飞机顺序随机,意味着不一定第一个人没票

考虑没票的人在第几个位置上飞机,如果他在最后一个位置上飞机,概率为1,否则为0.5

剩下的人上机顺序按照全排列搞就完事了,一共有m!种方案

式子列出来大概长这样:

1*(m-1)!+0.5*(m-1)*(m-1)! / m!

化简得出答案是(m+1)/2*m

代码:

#include <bits/stdc++.h>
#define int long long
#define sc(a) scanf("%lld",&a)
#define scc(a,b) scanf("%lld %lld",&a,&b)
#define sccc(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define schar(a) scanf("%c",&a)
#define pr(a) printf("%lld",a)
#define fo(i,a,b) for(int i=a;i<b;++i)
#define re(i,a,b) for(int i=a;i<=b;++i)
#define rfo(i,a,b) for(int i=a;i>b;--i)
#define rre(i,a,b) for(int i=a;i>=b;--i)
#define prn() printf("\n")
#define prs() printf(" ")
#define mkp make_pair
#define pii pair<int,int>
#define pub(a) push_back(a)
#define pob() pop_back()
#define puf(a) push_front(a)
#define pof() pop_front()
#define fst first
#define snd second
#define frt front()
#define bak back()
#define mem0(a) memset(a,0,sizeof(a))
#define memmx(a) memset(a,0x3f3f,sizeof(a))
#define memmn(a) memset(a,-0x3f3f,sizeof(a))
#define debug
#define db double
#define yyes cout<<"YES"<<endl;
#define nno cout<<"NO"<<endl;
using namespace std;
typedef vector<int> vei;
typedef vector<pii> vep;
typedef map<int,int> mpii;
typedef map<char,int> mpci;
typedef map<string,int> mpsi;
typedef deque<int> deqi;
typedef deque<char> deqc;
typedef priority_queue<int> mxpq;
typedef priority_queue<int,vector<int>,greater<int> > mnpq;
typedef priority_queue<pii> mxpqii;
typedef priority_queue<pii,vector<pii>,greater<pii> > mnpqii;
const int maxn=500005;
const int inf=0x3f3f3f3f3f3f3f3f;
const int MOD=100000007;
const db eps=1e-10;
int qpow(int a,int b){int tmp=a%MOD,ans=1;while(b){if(b&1){ans*=tmp,ans%=MOD;}tmp*=tmp,tmp%=MOD,b>>=1;}return ans;}
int lowbit(int x){return x&-x;}
int max(int a,int b){return a>b?a:b;}
int min(int a,int b){return a<b?a:b;}
int mmax(int a,int b,int c){return max(a,max(b,c));}
int mmin(int a,int b,int c){return min(a,min(b,c));}
void mod(int &a){a+=MOD;a%=MOD;}
bool chk(int now){}
int half(int l,int r){while(l<=r){int m=(l+r)/2;if(chk(m))r=m-1;else l=m+1;}return l;}
int ll(int p){return p<<1;}
int rr(int p){return p<<1|1;}
int mm(int l,int r){return (l+r)/2;}
int lg(int x){if(x==0) return 1;return (int)log2(x)+1;}
bool smleql(db a,db b){if(a<b||fabs(a-b)<=eps)return true;return false;}
db len(db a,db b,db c,db d){return sqrt((a-c)*(a-c)+(b-d)*(b-d));}
bool isp(int x){if(x==1)return false;if(x==2)return true;for(int i=2;i*i<=x;++i)if(x%i==0)return false;return true;}

int t,Case=1,n,m;

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
    sc(t);
    for(;Case<=t;++Case){
        db ansa,ansb;
        scc(n,m);
        if(n==1) ansa=1.0;
        else ansa=0.5;
        if(m==1) ansb=1.0;
        else ansb=(m+1.0)/(2.0*m);
        printf("Case #%d: ",Case);
        printf("%.6lf %.6lf\n",ansa,ansb);
    }
    return 0;
}

F、点有点权,边有边权,无向图,q个询问,每次询问从u到v的不经过点权大于w的点的最短路径长度(u和v的点权不考虑在内)

数据以邻接矩阵的形式给出,保证自己到自己的距离为0

首先任意两点一定是可达的,直接从起点走到终点完事,起点终点的点权都可以忽略

接下来考虑到n<200,估计floyd可以搞一搞

假设dp[k][i][j]表示在经过前k个点权最小的点的情况下,i到j的最短距离

那么先要把点权离散化一下,找到每个点对应点权的排名,ord[i]代表排名为i的点原来的编号,用pair按照第一维排序就行

对于每个询问,二分找到小于等于它的最大点权对应点的排名,输出dp[排名][x][y]即可

考虑转移方程:

dp[k][i][j]=min(dp[k-1][i][j],dp[k-1][i][mid]+dp[k-1][mid][j]);

其中mid代表排名为k的点编号,实际上也很好理解,对每个点枚举它做为中点,更新答案,只不过floyd起到了保存不同版本的最短路的作用罢了

并且dp[0][i][j]就代表原本两点间的距离

别忘了对原来的r数组排个序,否则二分的时候会出锅

代码:

#include <bits/stdc++.h>
#define int long long
#define sc(a) scanf("%lld",&a)
#define scc(a,b) scanf("%lld %lld",&a,&b)
#define sccc(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define schar(a) scanf("%c",&a)
#define pr(a) printf("%lld",a)
#define fo(i,a,b) for(int i=a;i<b;++i)
#define re(i,a,b) for(int i=a;i<=b;++i)
#define rfo(i,a,b) for(int i=a;i>b;--i)
#define rre(i,a,b) for(int i=a;i>=b;--i)
#define prn() printf("\n")
#define prs() printf(" ")
#define mkp make_pair
#define pii pair<int,int>
#define pub(a) push_back(a)
#define pob() pop_back()
#define puf(a) push_front(a)
#define pof() pop_front()
#define fst first
#define snd second
#define frt front()
#define bak back()
#define mem0(a) memset(a,0,sizeof(a))
#define memmx(a) memset(a,0x3f3f,sizeof(a))
#define memmn(a) memset(a,-0x3f3f,sizeof(a))
#define debug
#define db double
#define yyes cout<<"YES"<<endl;
#define nno cout<<"NO"<<endl;
using namespace std;
typedef vector<int> vei;
typedef vector<pii> vep;
typedef map<int,int> mpii;
typedef map<char,int> mpci;
typedef map<string,int> mpsi;
typedef deque<int> deqi;
typedef deque<char> deqc;
typedef priority_queue<int> mxpq;
typedef priority_queue<int,vector<int>,greater<int> > mnpq;
typedef priority_queue<pii> mxpqii;
typedef priority_queue<pii,vector<pii>,greater<pii> > mnpqii;
const int maxn=500005;
const int inf=0x3f3f3f3f3f3f3f3f;
const int MOD=100000007;
const db eps=1e-10;
int qpow(int a,int b){int tmp=a%MOD,ans=1;while(b){if(b&1){ans*=tmp,ans%=MOD;}tmp*=tmp,tmp%=MOD,b>>=1;}return ans;}
int lowbit(int x){return x&-x;}
int max(int a,int b){return a>b?a:b;}
int min(int a,int b){return a<b?a:b;}
int mmax(int a,int b,int c){return max(a,max(b,c));}
int mmin(int a,int b,int c){return min(a,min(b,c));}
void mod(int &a){a+=MOD;a%=MOD;}
bool chk(int now){}
int half(int l,int r){while(l<=r){int m=(l+r)/2;if(chk(m))r=m-1;else l=m+1;}return l;}
int ll(int p){return p<<1;}
int rr(int p){return p<<1|1;}
int mm(int l,int r){return (l+r)/2;}
int lg(int x){if(x==0) return 1;return (int)log2(x)+1;}
bool smleql(db a,db b){if(a<b||fabs(a-b)<=eps)return true;return false;}
db len(db a,db b,db c,db d){return sqrt((a-c)*(a-c)+(b-d)*(b-d));}
bool isp(int x){if(x==1)return false;if(x==2)return true;for(int i=2;i*i<=x;++i)if(x%i==0)return false;return true;}

int t,n,q,x,y,w;
int r[205],ord[205];
int dp[205][205][205];
vector<pii> v;

void floyd(){
    re(k,1,n){
        int mid=ord[k];
        re(i,1,n){
            re(j,1,n){
                dp[k][i][j]=min(dp[k-1][i][j],
                dp[k-1][i][mid]+dp[k-1][mid][j]);
            }
        }
    }
}

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
    cin>>t;
    re(Case,1,t){
        cin>>n>>q;
        v.clear();
        memmx(dp);
        re(i,1,n) cin>>r[i],v.pub(mkp(r[i],i));
        re(i,1,n) re(j,1,n) cin>>dp[0][i][j];
        sort(v.begin(),v.end());
        sort(r+1,r+1+n);
        re(i,1,n) ord[i]=v[i-1].snd;
        floyd();
        cout<<"Case #"<<Case<<":\n";
        while(q--){
            cin>>x>>y>>w;
            int p=upper_bound(r+1,r+1+n,w)-r;
            p--;
            cout<<dp[p][x][y]<<endl;
        }
    }
    return 0;
}

 

标签:Provincial,Multi,const,Contest,int,typedef,queue,lld,define
来源: https://www.cnblogs.com/oneman233/p/11475234.html