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 yingxiang720 at 2011-04-24 20:31:38 on Problem 1502
#include <iostream>
#include <memory.h>
#include <stdio.h>
#include <string.h>
#define MAX 0x7ffffff
using namespace std;

int map[105][105];
int vis[105];
int dist[105];

void init(int n)
{
    int i,j;
    for(i = 1;i <= n;i++)
        for(j = 1;j <= n;j++)
            map[i][j] = MAX;
    memset(vis,0,sizeof(vis));
}

int sturnd(char ch[])
{
    int sum = 0;
    int cs = strlen(ch);
    for(int i = 0;i < cs;i++)
    {
        sum *= 10;
        sum += (ch[i] - 48);
    }
    return sum;
}

int findMin(int n)
{
    int i,min = MAX,minNode = 0;
    for(i = 1;i <= n;i++)
        if(!vis[i] && dist[i] < min)
        {
            minNode = i;
            min = dist[i];
        }
    return minNode;
}
void dis(int n)
{
    int i,vnum,node;
    memset(vis,0,sizeof(vis));
    for(i = 1;i <= n;i++)   dist[i] = map[1][i];
    vis[1] = 1;
    vnum  = 1;
    while(vnum < n)
    {
        node = findMin(n);
        if(node)
        {
            vis[node] = 1;
            vnum ++;
            for(i = 1;i <= n;i++)
                if(!vis[i] && dist[node] + map[node][i] < dist[i])
                    dist[i] = dist[node] + map[node][i];
        }
        else break;
    }
}
int findMax(int n)
{
    int i,max = -1;
    for(i = 1;i <= n;i++)
        if(dist[i] != MAX && dist[i] > max)
            max = dist[i];
    return max;
}
int main()
{
    int n,i,j;
    char ch[100];
    cin >> n;
    init(n);
    for(i = 2;i <= n;i++)
        for(j = 1;j < i;j++)
        {
            cin >> ch;
            if(ch[0] == 'x')   map[i][j] = MAX;
            else    map[i][j] = map[j][i] = sturnd(ch);
        }
    dis(n);
    cout << findMax(n) << endl;
    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