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

Floyd为何也能16MS

Posted by speedcell4 at 2011-08-19 19:40:49 on Problem 1502
In Reply To:我只觉得输入挺麻烦的 Posted by:speedcell4 at 2011-08-19 19:24:11
#include<iostream>
#include<string>

using namespace std;

#define SIZE (101)
#define INF  (1<<29)
int n;
int map[SIZE][SIZE];

int findMax(int a,int b)
{
    return a>b?a:b;
}
int findMin(int a,int b)
{
    return a<b?a:b;
}
int ReadIn(void)
{
    string a; cin>>a;
    if(a=="x") return INF;
    else
    {
        int ans=0;
        for(int i=0,l=a.length();l-i>0;i++)
        {
            ans*=10;
            ans+=(a[i]-'0');
        }
        return ans;
    }
}
int floyd(void)
{
    for(int i=0;n-i>0;i++)
    {
        for(int j=0;n-j>0;j++)
        {
            for(int k=0;n-k>0;k++)
            {
                map[j][k]=findMin(map[j][k],map[j][i]+map[i][k]);
            }
        }
    }
    int ans=0;
    for(int i=1;n-i>0;i++)
    {
        ans=findMax(ans,map[0][i]);
    }
    return ans;
}         
int main()
{
    scanf("%d",&n);
    for(int i=0;n-i>0;i++)
    {
        map[i][i]=INF;
        for(int j=0;i-j>0;j++)
        {
            map[i][j]=map[j][i]=ReadIn();
        }
    }
    
    printf("%d\n",floyd());
    
    //system("pause");
    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