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代码

Posted by speedcell4 at 2011-08-19 11:45:02 on Problem 2241 and last updated at 2011-08-19 11:46:12
#include<iostream>
#define SIZE 1000
using namespace std;
int x,y,z;
int n,m,times=1,a[SIZE][SIZE];
struct node
{
    int x;
    int y;
    int z;
}b[SIZE];
int findMax(int a,int b)
{
    return a>b?a:b;
}
int main()
{
    while(scanf("%d",&n),n)
    {
        m=6*n;
        memset(a,-1,sizeof(a));
        for(int i=0,j=0;n-i>0;i++)
        {
            scanf("%d %d %d",&x,&y,&z);
            b[j].x=x; b[j].y=y; b[j].z=z; j++;
            b[j].x=x; b[j].y=z; b[j].z=y; j++;
            b[j].x=y; b[j].y=x; b[j].z=z; j++;
            b[j].x=y; b[j].y=z; b[j].z=x; j++;
            b[j].x=z; b[j].y=x; b[j].z=y; j++;
            b[j].x=z; b[j].y=y; b[j].z=x; j++;
        }
        for(int i=0;m-i>0;i++)
        {
            for(int j=0;m-j>0;j++)
            {
                if(b[i].x>b[j].x&&b[i].y>b[j].y)
                {
                    a[i][j]=b[i].z;
                }
            }
        }
        for(int i=0;m-i>0;i++)
        {
            for(int j=0;m-j>0;j++)
            {
                for(int k=0;m-k>0;k++)
                {
                    if(j==k) continue;
                    else if(a[j][i]!=-1&&a[i][k]!=-1)
                    {
                        a[j][k]=findMax(a[j][k],a[j][i]+a[i][k]);
                    }
                }
            }
        }
        int ans=0;
        for(int i=0;m-i>0;i++)
        {
            for(int j=0;m-j>0;j++)
            {
                ans=findMax(ans,a[i][j]+b[j].z);
            }
        }
        printf("Case %d: maximum height = %d\n",times++,ans);
    }
    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