编程介的小学生 2017-11-20 16:25 采纳率: 20.5%
浏览 634
已采纳

Electric wave

Problem Description
Ali was doing a physic experiment which requires him to observe an electric wave. He needs the height of each peak value and valley value for further study (a peak value means the value is strictly larger than its neighbors and a valley value means the value is strictly smaller than its neighbors). He did write these numbers down but he was too careless that he wrote them in a line without separations, such as “712495” may represent “7 12 4 9 5”. The only information he can remember was:
1. The data begins with a valley value
2. Each value is either a peak value or a valley value
Now he wants to insert blanks to make the data valid. If multiple solutions exist, he will choose the one with more blanks.

Input
The input consists several testcases.
The first line contains one integer N (1 <= N <= 100), the length of the data.
The second line contains one string S, the data he recorded.
S contains only digits.

Output
Print one integer, the maximum number of blanks he can insert.

Sample Input
6
712495

Sample Output
4

  • 写回答

2条回答 默认 最新

  • threenewbee 2018-09-15 11:49
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料