• hdu 3786 最短路


    题目很水,直接用Floyd即可

    /*
    * hdu3786/win.cpp
    * Created on: 2011-9-6
    * Author : ben
    */
    #include
    <cstdio>
    #include
    <cstdlib>
    #include
    <cstring>
    #include
    <cmath>
    #include
    <algorithm>
    using namespace std;

    #define SIZE 100
    #define MAX 0x7fffffff
    int map[SIZE][SIZE];
    int N;
    void init() {
    int i, j;
    for (i = 0; i < N; i++) {
    for (j = 0; j < N; j++) {
    map[i][j]
    = MAX;
    }
    map[i][i]
    = 0;
    }
    }
    void Floyd() {
    int i, j, k;
    for (k = 0; k < N; k++) {
    for (i = 0; i < N; i++) {
    for (j = 0; j < N; j++) {
    if (map[i][k] < map[i][j] - map[k][j]) {
    map[i][j]
    = map[i][k] + map[k][j];
    }
    }
    }
    }
    }

    void work() {
    int n, m, a, b, temp;
    char input[20];
    N
    = 26;
    while (scanf("%d %d", &n, &m) == 2) {
    if (n == 0 && m == 0) {
    break;
    }
    init();
    for (int i = 0; i < n; i++) {
    scanf(
    "%s", input);
    a
    = input[0] - 'A';
    if (input[1] != '-') {
    b
    = input[1] - 'A';
    map[a][b]
    = 1;
    }
    if (input[2] != '-') {
    b
    = input[2] - 'A';
    map[a][b]
    = 1;
    }
    }
    Floyd();
    for (int i = 0; i < m; i++) {
    scanf(
    "%s", input);
    a
    = input[0] - 'A';
    b
    = input[1] - 'A';
    if (map[a][b] < MAX) {
    temp
    = map[a][b];
    while (temp > 2) {
    printf(
    "great-");
    temp
    --;
    }
    if (temp > 1) {
    printf(
    "grand");
    }
    printf(
    "child");
    }
    else if (map[b][a] < MAX) {
    temp
    = map[b][a];
    while (temp > 2) {
    printf(
    "great-");
    temp
    --;
    }
    if (temp > 1) {
    printf(
    "grand");
    }
    printf(
    "parent");
    }
    else {
    putchar(
    '-');
    }
    putchar(
    '\n');
    }
    }
    }

    int main() {
    #ifndef ONLINE_JUDGE
    freopen(
    "data.in", "r", stdin);
    #endif
    work();
    return 0;
    }
  • 相关阅读:
    windows10 应用商店(Microsoft store)进不去
    Java中System函数
    人生的智慧叔本华
    第2关:文本串里单词、数字和符号的识别
    C/C++语言编写PL/0编译程序的词法分析程序
    编译原理实践
    vanced 无法登录问题
    @bizresubmit
    《道德经》全文(翻译 )
    道德经第十章
  • 原文地址:https://www.cnblogs.com/moonbay/p/2169689.html
Copyright © 2020-2023  润新知