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 |
大虾请看?#include<iostream.h> int main() { double a[1010],b[1010]; int n,k; while(cin>>n>>k) { if(n==0&&k==0)break; int i,j; double c[1010]={0}; for(i=0;i<n;i++) { cin>>a[i]; } for(i=0;i<n;i++) { cin>>b[i]; } double aa=0.,bb=0.; double max=0; int cur; for(i=0;i<n;i++) { if(a[i]/b[i]>max) { max=a[i]/b[i]; cur=i; } } aa+=a[cur]; bb+=b[cur]; c[cur]=1; int count=1; for(i=0;i<n;i++) { if(c[i]==0) { double start=(aa+a[i])/(bb+b[i]); cur=i; for(j=0;j<n;j++) { if(c[j]==0&&i!=j) { double run=(aa+a[j])/(bb+b[j]); if(run>start) { start=run; cur=j; } } } count++; c[cur]=1; aa+=a[cur]; bb+=b[cur]; if(count>=n-k)break; } } // cout<<aa<<" "<<bb<<endl; cout<<(int)(100*aa/bb+0.5)<<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