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

Re:程序有什么错误

Posted by whitesea at 2006-09-18 20:19:11 on Problem 1701
In Reply To:程序有什么错误 Posted by:savon_cn at 2006-09-17 01:21:09
> #include<iostream>
> using namespace std;
> int aa[10000];
> double up[10000];
> double down[10000];
> int N,a,b;
> int nPos=1;
> void UpSum()
> {
>   double pcount=aa[N-1];
>   double addnum=0;
>   up[0]=0;
>   for(int i=0;i<N-1;i++)
>   {
> 	  up[i+1]=up[i]+pcount*a+addnum;
> 	  addnum+=pcount;
> 	  pcount+=aa[N-i-2];
>   }
> }
> void DownSum()
> {
>   double pcount=aa[0];
>   double addnum=0;
>   down[0]=0;
>   for(int i=0;i<N-1;i++)
>   {
> 	  down[i+1]=down[i]+pcount*b+addnum;
> 	  addnum+=pcount;
> 	  pcount+=aa[i+1];	  
>   }
> }
> void FindSoul()
> {
>   double best=down[0]+up[N-1];
>   for(int i=0;i<N;i++)
>   {
>       if(down[i]+up[N-i-1]<best)
> 	  {
> 		  best=down[i]+up[N-i-1];
> 		  nPos=i+1;
> 	  }
>   }	  
> }
> 
> void main()
> {
> 	int M;
> 	cin>>M;
> 	if(M>20||M<1)
> 	  return;
>   for(int jj=0;jj<M;jj++)
>   {
>   cin>>N>>a>>b;
>   if(a>100||a<0||b>100||b<0) return;
>   if(N>10000||N<=0) return;
>   for(int i=0;i<N;i++)
>   {
> 	  cin>>aa[i];
> 	  if(aa[i]>20||aa[i]<0) return;
>   }
>   DownSum();
>   UpSum();
>   FindSoul();
>   cout<<nPos<<endl;
>   }
> }

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