| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
this is my code, did i get it right??#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator