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 |
谁能帮我看看呀,wa了一个晚上,实在是查不出错了,贪心法应该过的呀,thx//按照lrj的书上的算法做的,减掉路程的时间后,每次选最大的钓鱼量 #include<iostream> #include<fstream> #include<algorithm> using namespace std; int main(){ ifstream cin("tmp.txt"); int h,n,f[26],d[26],t[26]; while(cin>>n&&n!=0){ cin>>h; h*=12; int i,j,k; for(i=0;i<n;i++){ cin>>f[i]; } for(i=0;i<n;i++){ cin>>d[i]; } t[0]=0; for(i=1;i<n;i++){ cin>>t[i]; } int res[26]={0}; int max_s=0; for(j=0;j<=n-1;j++){ int ff[26]; for(i=0;i<26;i++){ ff[i]=f[i]; } h-=t[j]; if(h<=0)break; int count[26]={0}; int s=0; int pos; for(i=0;i<h;i++){ int max_=ff[0]; //找最大元素 pos=0; for(k=0;k<=j;k++){ if(ff[k]>max_){ max_=ff[k]; pos=k; } } s+=ff[pos]; count[pos]++; //计数 ff[pos]-=d[pos]; if(ff[pos]<=0)ff[pos]=0; } if(max_s<s){ max_s=s; for(i=0;i<n;i++){ res[i]=count[i]; } } } for(i=0;i<n;i++){ cout<<res[i]*5; if(i==n-1)cout<<endl; else cout<<", "; } cout<<"Number of fish expected: "<<max_s<<endl; cout<<endl; } system("pause"); return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator