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

this is my code, did i get it right??

Posted by hasan83 at 2007-05-05 05:22:13 on Problem 3231
#include<iostream>
#include<iomanip>
using namespace std;

int main()
{
    int n,t,k=0;
    while(cin>>n&&n!=0)
    {
       cin>>t;
       long double p[100]={0},s[100]={0},m[100]={0},time[100]={0};
       for(int i=0;i<n;i++)
       {
           cin>>p[i]>>s[i]>>m[i];    
       }
       long double finished=0,extra_band=0;
       while(finished<n)
       {
      /*    for(int i=0;i<n;i++)
          {
              cout<<p[i]<<" "<<s[i]<<" "<<m[i]<<" "<<time[i]<<endl;    
          }              
          cout<<"-----------------------"<<endl;
          system("pause");*/
          long double ct[100]={0};
          int index=-1;
          for(int j=0;j<n;j++)
          {
             if(p[j]!=0)     
             {
                 ct[j]=(p[j])/s[j];
                 if(index==-1||ct[j]<ct[index])index=j;     
             }
          }
          time[index]=ct[index];
          for(int j=0;j<n;j++)
          {
             if(p[j]!=0)
             {     
                 p[j]=p[j]-ct[index]*s[j];
                 if(p[j]==0)
                 {
                    time[j]=time[index];
                    extra_band+=s[j];
                    finished++;        
                 }
             }    
          }
          int dis=1;
          while(extra_band!=0&&dis)
          {                     
              dis=0;
              int not_finished=0;                    
              for(int j=0;j<n;j++)
              {
                 if(p[j]!=0&&s[j]!=m[j])
                 {
                    not_finished++;                    
                 }     
              }
              long double share=(extra_band)/not_finished;
              for(int j=0;j<n;j++)
              {
                 if(p[j]!=0&&s[j]!=m[j])
                 {
                    s[j]+=share;
                    extra_band-=share;
                    if(s[j]>m[j])
                    {
                        extra_band+=s[j]-m[j];
                        s[j]=m[j];         
                    }                    
                 }     
              }
          }
       }
       cout<<"Case "<<++k<<":"<<endl;
       long double sum=0;
       for(int i=0;i<n;i++)
       {
          sum+=time[i];
          cout<<fixed<<setprecision(3)<<"NO"<<i+1<<":"<<sum<<"s"<<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