编程介的小学生 2019-04-26 00:59 采纳率: 20.5%
浏览 173

输出序列开头的元素的做法,利用C语言的程序的射击的语言的方式

Problem Description

Do you still remember the movie "I, robot" ? In that movie, Sunny is a very special, unique robot who can dream! As we known, robot is a machine installed with artificial intelligence, and it can't response to the situations which are not contained in the pre-designed programs. But the creator of Sunny detects that the logic sequences existed in the robot would change under some particular cases, e.g. magnetic field, noises etc. He called this unpredictable sequence ghosts in the robot because these random combination of 1s and 0 s could yield unpredictable behaviors of robots, it was terrible! In order to detect this situation as soon as possible, you should help the prof. via your outstanding programming skills.
You would be given a sequence with the length of N, and this sequence is only contained 0 and 1.Based on the professor's recent research data, the sequence could have at most F successive bits flipped(that means 0 changes to 1, and 1 changes to 0) and could have at most R successive bits remained the same. Based on these situations, you should calculate the maximum number of 1 in the sequence after those changes.

Input
The input would have multiple test cases, each test case has two lines, The first line contains two integer R and F(1 <= R <= 50, 1 <= F <= 50), indicating the number of the digits remain the same and the number of the digits flipped respectively. the second line is a sequence only comprises of 0 and 1, whose length is between 1 and 1000.The input would end when R == 0 and F == 0.

Output
For each case, print a line with the maximum number of 1 left in the sequence.

Sample Input
4 1
1111
2 2
1111
0 0

Sample Output
4
3

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
    • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
    • ¥50 有数据,怎么用matlab求全要素生产率
    • ¥15 TI的insta-spin例程
    • ¥15 完成下列问题完成下列问题
    • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
    • ¥15 YoloV5 第三方库的版本对照问题
    • ¥15 请完成下列相关问题!
    • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
    • ¥15 求daily translation(DT)偏差订正方法的代码