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。。前面给的所有数据都测试过了 没有错误,是在找不到原因了,希望大牛们解释下。。。感激不尽啊。。。。#include<stdio.h> #include<stdlib.h> #include<iostream> #define PT 256 using namespace std; int getShu(int lake[],int n) { int max=0; for(int i=1;i<n;i++) { if(lake[i]>lake[max]) max=i; } return max; } int findMax(int n,int h,int Line[],int lake1[],int dec1[]) { int lake[PT],dec[PT]; for(int i=0;i<n;++i) { lake[i]=lake1[i]; dec[i]=dec1[i]; Line[i]=0; } Line[n-1]=1; int max=0; max+=lake[n-1]; lake[n-1]-=dec[n-1]; if(lake[n-1]<0) lake[n-1]=0; for(int i=0;i<h-1;++i) { int j=getShu(lake,n); max+=lake[j]; Line[j]++; lake[j]-=dec[j]; if(lake[j]<0) lake[j]=0; } return max; } int Line[PT]; int p[PT]; int lake1[PT],dec1[PT],road[PT]; int main() { int n,h; int max=-1; while(1) { for(int i=0;i<PT;i++) p[i]=0; cin>>n; if(n==0) break; cin>>h; for(int i=0;i<n;++i) cin>>lake1[i]; for(int i=0;i<n;++i) cin>>dec1[i]; road[0]=0; for(int i=0;i<PT;i++) Line[i]=0; for(int i=1;i<n;++i) { cin>>road[i]; road[0]+=road[i]; } h=12*h-road[0]; road[n]=0; for(int i=0;i<n;++i) { h=h+road[n-i]; if(h<=0) continue; if(findMax( n-i, h, Line,lake1,dec1)>=max) { max=findMax( n-i, h, Line,lake1,dec1); for(int j=0;j<n;j++) { p[j]=Line[j]*5; } for(int k=0;k<PT;k++) Line[k]=0; } } for(int i=0;i<n-1;++i) { cout<<p[i]<<','<<' '; } cout<<p[n-1]<<endl; cout<<"Number of fish expected: "<<max<<endl; cout<<endl; max=0; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator