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

看看我的程序,到底哪里不对啊? runtime error 是怎么回事啊?

Posted by pmars at 2010-03-25 12:42:42 on Problem 1926

//pku 1926

#include <iostream>
#include <vector>
#include <iomanip>

using namespace std ;

class Tank
{
public :
    vector<int> link ;
    double data ;
    int pipe ;
    bool use ;
} ;

class System
{
private :
    int m , n ;
    Tank tank[105] ;
    void doEmpty() ;
    void doRun(vector<int>& vt,int k) ;
public :
    void input() ;
    void run() ;
    void output() ;
} ;

void System::doEmpty()
{
    for ( int i = 1 ; i <= n ; ++ i )
    {
        tank[i].link.clear() ;
    }
}

void System::input()
{
    cin>>n>>m ;
    int temp , i ;
    for( i = 1 ; i <= n ; ++ i )
    {
        cin>>temp ;
        tank[i].data = temp ;
        tank[i].use = false ;
    }
    int one , two ;
    for ( i = 0 ; i < m ; ++ i )
    {
        cin>>one>>two ;
        tank[one].link.push_back(two) ;
        tank[two].link.push_back(one) ;
    }
    for ( i = 1 ; i <= n ; ++ i )
    {
        tank[i].pipe = tank[i].link.size() ;
    }
}

void System::doRun(vector<int> & vt,int k )
{
    for ( int j = 0 ; j < tank[k].pipe ; ++ j )
    {
        if ( ! (tank[tank[k].link[j]].use ) )
        {
            vt.push_back(tank[k].link[j]) ;
            tank[tank[k].link[j]].use = true ;
        }
    }      
}

vector<int> vt ;

void System::run()
{

    for ( int i = 1 ; i <= n ; ++ i )
    {
        double sum = 0 ;
        int pipe = 0 ;
        vt.clear() ;  
        if ( (! tank[i].use) && tank[i].pipe )
        {
             vt.push_back(i) ;
             tank[i].use = true ;
             for ( unsigned p = 0 ; p < vt.size() ; ++ p )
             {
                 int k = vt[p] ;
                 doRun(vt,k) ;
                 sum += tank[k].data ;
                 pipe += tank[k].pipe ;
             }
        }
        for ( unsigned j = 0 ; j < vt.size() ; ++ j )
        {
            tank[vt[j]].data = tank[vt[j]].pipe * sum / pipe ;
        } 
        
    }
}

void System::output()
{
    for ( int i = 1 ; i <= n ; ++ i )
    {
        cout<<setiosflags(ios::fixed)<<setprecision(3)<<tank[i].data<<endl ;
    }
    cout<<endl;
    doEmpty() ;
}

int main()
{
    
    int times ;
    cin>>times ;
    while ( times -- )
    {
        System s ;
        s.input() ;
        s.run() ;
        s.output() ;
    }

    return 0 ;
}


运行的时候runtime error

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