码迷,mamicode.com
首页 > 其他好文 > 详细

ICPC 2019宁夏网络赛

时间:2019-08-31 19:12:42      阅读:151      评论:0      收藏:0      [点我收藏+]

标签:max   scan   chinese   for   blank   bool   its   https   acm   

 ICPC 2019宁夏网络赛

Maximum Element In A Stack

 

Rolling The Polygon

 

Caesar Cipher

 

Take Your Seat

 

Moving On

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,m,k,q;
int dp[210][210][210];
int d[210],id[210];
bool cmp(int x,int y) {
    return d[x] < d[y];
}
int main() {
    int _,ca=0;
    scanf("%d", &_);
    while (_--) {
        memset(dp, 0x3f, sizeof(dp));
        scanf("%d%d", &n, &q);
        for (int i = 1; i <= n; i++) {
            scanf("%d", &d[i]);
            id[i] = i;
        }
        sort(id + 1, id + 1 + n, cmp);
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= n; j++) {
                scanf("%d", &dp[0][i][j]);
            }
        }
        for (int k = 1; k <= n; k++) {
            for (int i = 1; i <= n; i++) {
                for (int j = 1; j <= n; j++) {
                    dp[k][i][j] = min(dp[k - 1][i][j], dp[k - 1][i][id[k]] + dp[k - 1][id[k]][j]);
                }
            }
        }
        printf("Case #%d:\n",++ca);
        for (int i = 1; i <= q; i++) {
            int u, v, w;
            scanf("%d%d%d", &u, &v, &w);
            int k = 0;
            for (int i = 1; i <= n; i++) {
                if (d[id[i]] <= w) {
                    k = i;
                }
            }
            printf("%d\n", dp[k][u][v]);
        }
    }
    return 0;
}

  

ICPC 2019宁夏网络赛

标签:max   scan   chinese   for   blank   bool   its   https   acm   

原文地址:https://www.cnblogs.com/Accpted/p/11440051.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!