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 |
I wrote the program but unaccepted,why?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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator