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 niyuzhe at 2007-07-17 20:54:47 on Problem 2472
#include<iostream>
#include<iomanip>
using namespace std;

double map[110][110];
int mark[110];

int main()
{
    int n,m;
    while(1)
    {
        scanf("%d",&n);
        //cout<<n<<endl;
        if(!n)
            break;
        scanf("%d",&m);
        //cout<<m<<endl;
        memset(map,0,sizeof(map));
        memset(mark,0,sizeof(mark));
        int a,b;
        double p;
        for(int i=0;i<m;i++)
        {
            scanf("%d%d%lf",&a,&b,&p);
            //cin>>p;
            //cout<<a<<b<<p<<endl;
            p/=100;
            map[a][b]=p;
            map[b][a]=p;
        }
        int s=1;
        double po=1;
        while(s!=n)
        {
            int min=-1;
            int minI;
            for(int i=1;i<=n;i++)
            {
                if(!mark[i]&&map[s][i])
                {
                    if(map[s][i]>min)
                    {
                        minI=i;
                    }
                }
            }
            mark[minI]=1;
            po*=map[s][minI];
            s=minI;
        }
        cout<<fixed<<setprecision(6)<<po*100<<" percent"<<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