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

I wrote the program but unaccepted,why?

Posted by RUNSLOWLY at 2008-07-10 11:24:09 on Problem 2313
In Reply To:Re:算法提示!给未AC的人!(已AC!) Posted by:RUNSLOWLY at 2008-07-10 11:21:38
//my program
 #include<iostream>
#include<math.h>
using namespace std;
int  main()
{
	int n,i,v,a[100],b[100];
	cin>>n;
	for(i=0;i<n;i++)
	{
		cin>>a[i];
		b[i]=a[i];
	}
	for(i=1;i<n-1;i++)
	{
		if(b[i-1]<=a[i]&&b[i+1]>=a[i])
			b[i]=a[i];
		else
			if(b[i-1]>=a[i]&&b[i-1]<=b[i+1])
				b[i]=b[i-1];
			else
				b[i]=b[i+1];
	}
	v=0;
	for(i=0;i<n;i++)
		v+=abs(a[i]-b[i]);
	for(i=0;i<n-1;i++)
		v+=abs(b[i]-b[i+1]);
	cout<<v<<endl;
	return 0;
}






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