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 |
发代码~~自以为还是比较简洁的。。。求不喷。。。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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator