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

发代码~~自以为还是比较简洁的。。。求不喷。。。

Posted by lpl1998 at 2014-08-23 11:17:06 on Problem 2181
bool turn = 0;
int ans = 0;
for(int i = 1; i <= n; i++)
{
	if(!turn && a[i] > a[i+1]) ans += a[i], turn = 1-turn;
	if(turn && a[i] < a[i+1])  ans -= a[i], turn = 1-turn;
}
大概思路就是在每个转折点的时候进行操作
加上波峰,减去波谷

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