PAT - 1003 Emergency (25)

As an emergency rescue team leader of a city, you are given a special map of your country. The map shows several scattered cities connected by some roads. Amount of rescue teams in each city and the length of each road between any pair of cities are marked on the map. When there is an emergency call to you from some other city, your job is to lead your men to the place as quickly as possible, and at the mean time, call up as many hands on the way as possible.

Input

Each input file contains one test case. For each test case, the first line contains 4 positive integers: N (<= 500) - the number of cities (and the cities are numbered from 0 to N-1), M - the number of roads, C1 and C2 - the cities that you are currently in and that you must save, respectively. The next line contains N integers, where the i-th integer is the number of rescue teams in the i-th city. Then M lines follow, each describes a road with three integers c1, c2 and L, which are the pair of cities connected by a road and the length of that road, respectively. It is guaranteed that there exists at least one path from C1 to C2.

Output

For each test case, print in one line two numbers: the number of different shortest paths between C1 and C2, and the maximum amount of rescue teams you can possibly gather. All the numbers in a line must be separated by exactly one space, and there is no extra space allowed at the end of a line.

Sample Input

5 6 0 2
1 2 1 5 3
0 1 1
0 2 2
0 3 1
1 2 1
2 4 1
3 4 1

Sample Output

2 4


【题目大意】作为一个城市紧急救援队的队长,你将会得到一张特殊的关于你的城市的地图。这个地图展示了道路连接着若干分散的城市。每一个城市救援队的数量以及每对城市间道路的长度都标在地图上。当从某个别的城市打来紧急电话时,你的任务是带领你的队伍尽可能快地到达那个城市,同时在路上带上尽可能多的人。
【输入】
第一行:N, M, C1 C2
N - 城市的数量(城市编号 0 ~ N-1)
M - 道路的数量
C1 - 起点
C2 - 终点
第二行:每个城市救援队的数量
剩下:c1 c2 L
连接城市 c1 与城市 c2 的道路的长度为 L
【输出】C1 到 C2 的最短距离和救援队数量

【数据范围】N <= 500

L没有给范围???

【解题思路】Dijkstra 模板稍微改一下。在更新最短路的时候加一个判断,路径相等但是救援队数量相比较多的情况也可以更新。


#include<bits/stdc++.h>
using namespace std;
const int MAXN = 500+10;
const int INF = 0x3f3f3f3f;
int mat[MAXN][MAXN];
int val[MAXN];
int dis[MAXN], ans[MAXN], path[MAXN];
bool vis[MAXN]; 
int n, m, c1, c2;
void dj() {
    fill(dis, dis+MAXN, INF);
    dis[c1] = 0;
    ans[c1] = val[c1];
    path[c1] = 1;
    for (int i = 0; i < n; i++) {
        int v = -1, minn = INF;
        for (int j = 0; j < n; j++) {
            if (!vis[j] && dis[j] < minn) {
                minn = dis[j];
                v = j;
            }
        }
        if (v == -1) break; 
        vis[v] = 1;
        for (int j = 0; j < n; j++) {
            if (vis[j]) continue;
            if (dis[v] + mat[v][j] < dis[j]) {
                dis[j] = dis[v] + mat[v][j];
                path[j] = path[v];
                ans[j] = ans[v] + val[j]; 
            } else if (dis[v] + mat[v][j] == dis[j]) {
                path[j] += path[v];
                if (ans[v] + val[j] > ans[j])
                    ans[j] = ans[v] + val[j]; 
            }
        }
    }
}

int main() {
    scanf("%d%d%d%d", &n, &m, &c1, &c2);
    for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++)
        mat[i][j] = INF;
    for (int i = 0; i < n; i++)
        scanf("%d", &val[i]);
    for (int i = 0; i < m; i++) {
        int a, b, c;
        scanf("%d%d%d", &a, &b, &c);
        mat[a][b] = mat[b][a] = c;
    }
    dj();
    printf("%d %d\n", path[c2], ans[c2]);

    return 0;
}

提交时间状态分数题目编译器耗时
2018/7/6 22:33:46答案正确251003C++ (g++)5 ms
2018/7/6 22:27:29部分正确91003C++ (g++)5 ms
2018/7/6 21:59:57答案错误01003C++ (g++)4 ms

模板背得乱七八糟……硬生生 debug 半小时 ˃̣̣̥᷄⌓˂̣̣̥᷅

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
项目:使用 JavaScript 编写的杀死幽灵游戏(附源代码) 杀死鬼魂游戏是使用 Vanilla JavaScript、CSS 和 HTML 画布开发的简单项目。这款游戏很有趣。玩家必须触摸/杀死游荡的鬼魂才能得分。您必须将鼠标悬停在鬼魂上 - 尽量得分。鬼魂在眨眼间不断从一个地方移动到另一个地方。您必须在 1 分钟内尽可能多地杀死鬼魂。 游戏制作 这个游戏项目只是用 HTML 画布、CSS 和 JavaScript 编写的。说到这个游戏的特点,用户必须触摸/杀死游荡的幽灵才能得分。游戏会根据你杀死的幽灵数量来记录你的总分。你必须将鼠标悬停在幽灵上——尽量得分。你必须在 1 分钟内尽可能多地杀死幽灵。游戏还会显示最高排名分数,如果你成功击败它,该分数会在游戏结束屏幕上更新。 该游戏包含大量的 javascript 以确保游戏正常运行。 如何运行该项目? 要运行此游戏,您不需要任何类型的本地服务器,但需要浏览器。我们建议您使用现代浏览器,如 Google Chrome 和 Mozilla Firefox。要玩游戏,首先,单击 index.html 文件在浏览器中打开游戏。 演示: 该项目为国外大神项目,可以作为毕业设计的项目,也可以作为大作业项目,不用担心代码重复,设计重复等,如果需要对项目进行修改,需要具备一定基础知识。 注意:如果装有360等杀毒软件,可能会出现误报的情况,源码本身并无病毒,使用源码时可以关闭360,或者添加信任。
javascript 中的 Paint War Game 是使用 HTML、CSS 和 JavaScript 开发的。谈到游戏玩法,这款游戏的主要目标是建造比敌人更多的油漆砖。您所要做的就是使用 WASD 键输入玩家的动作。您可以使用 VS Code 来运行该项目。 关于项目 每次您的玩家走过一块瓷砖时,它都会被涂成您的团队颜色。您必须在同一块瓷砖上走 4 次才能获得更多游戏点数。瓷砖会被您的团队挡住,并且不能再被偷走。如果您走过另一支球队的瓷砖,它会像您第一次走过时一样被涂上颜色。如果您创建一个封闭的被阻挡瓷砖图形,图形内所有未被阻挡的瓷砖都将固定为您的团队颜色。这个游戏充满乐趣,创造和重新即兴发挥会更有趣。 要运行此项目,我们建议您使用现代浏览器,例如 Google Chrome、  Mozilla Firefox。该游戏可能还支持 Explorer/Microsoft Edge。 演示: javascript 中的 Paint War Game 是使用 HTML、CSS 和 JavaScript 开发的。谈到游戏玩法,这款游戏的主要目标是建造比敌人更多的油漆砖。您所要做的就是使用 WASD 键输入玩家的动作。您可以使用 VS Code 来运行该项目。 关于项目 每次您的玩家走过一块瓷砖时,它都会被涂成您的团队颜色。您必须在同一块瓷砖上走 4 次才能获得更多游戏点数。瓷砖会被您的团队挡住,并且不能再被偷走。如果您走过另一支球队的瓷砖,它会像您第一次走过时一样被涂上颜色。如果您创建一个封闭的被阻挡瓷砖图形,图形内所有未被阻挡的瓷砖都将固定为您的团队颜色。这个游戏充满乐趣,创造和重新即兴发挥会更有趣。 要运行此项目,我们建议您使用现代浏览器,例如 Google Chrome、  Mozilla Firefox。该游戏可能还支持 Explorer/Microsoft Edge。 演示: 该项目为国外大神项目,可以作为毕业设计的项目,也可以作为大作业项目,不用担心代码重复,设计重复等,如果需要对项目进行修改,需要具备一定基础知识。 注意:如果装有360等杀毒软件,可能会出现误报的情况,源码本身并无病毒,使用源码时可以关闭360,或者添加信任。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值