Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

菜鸟搜索 没想到能过 高兴 嘿嘿嘿

Posted by zcube at 2011-03-15 20:42:05 on Problem 2263
#include <stdio.h>
#include <string.h>

int n, f, max, k;
int map[201][201], mark[201][201];
char city[201][31], c[31];

int num() //把城市编成号码
{
    int num, i = 0;
    if(k > 0)
    for (i=1; i<=k; i++)
        if (strcmp(city[i], c) == 0)
        {
            num = i;
            break;
        }
    if (i > k || k == 0){
        strcpy(city[++k], c);
        num = k;
    }
    return num;
}

void search(int i, int dj) //dj代表权值
{
    if (max >= dj)  return;  //剪枝

    if (i == f)
    {
        max = dj;
        return;
    }


    for (int j=1; j<=n; j++)
    {
        if (mark[i][j]) //剪枝 已搜索
            return;
        if (map[i][j])
        {
            mark[i][j] = 1;
            if (dj <= map[i][j])
                    search(j, dj);
            else    search(j, map[i][j]);
        }
    }

    return;
}

int main()
{
    int r, a, b, w, count = 1;
    while (scanf("%d%d", &n, &r), n, r)
    {
        memset(map, 0, sizeof (map));
        memset(mark, 0, sizeof (mark));
        k = 0;
        while (r--)
        {
            scanf("%s", c);
            a = num();
            scanf("%s", c);
            b = num();
            scanf("%d", &w);
            map[a][b] = map[b][a] = w;
        }
        scanf("%s", c);
        a = num();
        scanf("%s", c);
        f = num();
        max = 0;
        search(a, 10001);//从起始城市搜索 把权值赋为最大

        printf("Scenario #%d\n%d tons\n\n", count++, max);
    }
    return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator