The Way to Home (模拟)

音视频开发(一)RTSP模拟环境搭建 要进行音视频相关的开发,除了需要掌握音视频相关的协议、格式、工具、语言、库以外,模拟环境也是非常重要的条件。有了模拟环境,我们才能随时测试、更改自己写的音视频代码。比如,我们要进行RTSP播放器开发,就需要模拟RTSP媒体源;要进行RTSP客户端开发,就需要模拟的RTSP服务器;要进行RTSP服务器开发,就需要模拟的推流、拉流。 阅读详情

The Way to Home


A frog lives on the axis Ox and needs to reach home which is in the point n. She starts from the point 1. The frog can jump to the right at a distance not more than d. So, after she jumped from the point x she can reach the point x + a, where a is an integer from 1 to d.

For each point from 1 to n is known if there is a lily flower in it. The frog can jump only in points with a lilies. Guaranteed that there are lilies in the points 1 and n.

Determine the minimal number of jumps that the frog needs to reach home which is in the point n from the point 1. Consider that initially the frog is in the point 1. If the frog can not reach home, print -1.


Input

The first line contains two integers n and d (2 ≤ n ≤ 100, 1 ≤ d ≤ n - 1) — the point, which the frog wants to reach, and the maximal length of the frog jump.

The second line contains a string s of length n, consisting of zeros and ones. If a character of the string s equals to zero, then in the corresponding point there is no lily flower. In the other case, in the corresponding point there is a lily flower. Guaranteed that the first and the last characters of the string s equal to one.

Output

If the frog can not reach the home, print -1.

In the other case, print the minimal number of jumps that the frog needs to reach the home which is in the point n from the point 1.

Examples
Input
8 4
10010101
Output
2
Input
4 2
1001
Output
-1
Input
8 4
11100101
Output
3
Input
12 3
101111100101
Output
4
Note

In the first example the from can reach home in two jumps: the first jump from the point 1 to the point 4 (the length of the jump is three), and the second jump from the point 4 to the point 8 (the length of the jump is four).

In the second example the frog can not reach home, because to make it she need to jump on a distance three, but the maximum length of her jump equals to two.

给定n,d,两个整数,然后一个01字符串,n是这个字符串的长度,青蛙只能向右跳,d是每次它向右跳的最大步数,要求每次只能跳到1上,问青蛙从1跳到n最少跳几次

我的思路是从1起点开始,先加上最大跳跃步数,然后从这个下标往回找找到1,更新起点,答案加一,否则不能到达输出-1

code:

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int main(){
    char s[109];
    int n,d;
    scanf("%d%d",&n,&d);
    getchar();
    for(int i = 1; i <= n; i++){
        scanf("%c",&s[i]);
    }
    int i = 1;
    int ans = 0;
    while(i <= n){//起点
        int j = i + d;//每次从起点跳最远到达的下标
        if(j > n){//如果从起点跳的最远下标超过了n肯定可达并结束
            ans++;
            break;
        }
        int flag = 0;
        while(j > i){
            if(s[j] == '1'){//找到第一个1停止
                ans++;
                flag = 1;
                i = j;
                break;
            }
            j--;
        }
        if(i == n) break;//如果恰好到了n退出循环
        if(!flag){//如果没有1说明不能到达
            printf("-1\n");
            return 0;
        }
    }
    printf("%d\n",ans);
    return 0;
}


Python相关环境变量配置和模拟手机app登录 C:\Program Files\Java\jdk1.8.0_201(这里是你的安装路径,最好复制粘贴)接下来我们开始测试。在F盘新建一个java文件。我的是debug.java。接着,打开系统->高级系统设置->环境变量。新建一个JAVA_HOME。然后打开cmd,输入javac,若出现以下信息,则证明你成功了一半。输入java,若出现以下信息,则证明java环境变量配置成功了。然后成功输出10.java环境检验成功。【java环境变量配置】然后在Path下添加。 阅读详情

相关推荐

模拟器下载安装【用于monkey测试】

1.下载mumu模拟器 下载mumu的网址:http://mumu.163.com/ 下载的是Windows64位,安卓版测试的模拟器 2.

lovelygirlyuzhu的博客 3644

P13534 [OOI 2023] The way home / 回家的路 题解

如果可以,求出他至少需要举办多少场表演。现在,布迪尼需要踏上回家的旅程,目标是回到编号为。输出一个整数,表示布迪尼至少需要举办的表演场数。,也就是用将工作次数差值用于赚更靠后的钱,赚的一定比在之前赚更多。),分别表示城市数量、航班数量、初始卢布数和测试组编号。块钱,在一条边上移动需花费边权,在一个点工作一次赚。在第一个样例中,布迪尼最优策略是在第一个城市举办。在第二个样例中,布迪尼最优策略是在第一个城市举办。),表示在每个城市举办一场表演能获得的收入。,他都可以随时举办魔术表演,每场表演能赚。

MYJ_aiie的博客 2023

用python实现对Gitee的模拟登陆

title: 码云模拟登陆 date: 2022-05-11 07:39:04 tags: Gitee Python categories: Python 两种方法是先对码云的模拟登陆 1、使用cookies发起request请求。 ‘’’ 功能:带入cookies模拟gitee用户登录 实现:重写strart_request方法,再就是把请求cookies转成字典 scrapy startproject gitee scrapy genspider git1 gitee.com ‘’’ impo

YTNetMan的博客 834

The Way to Home (模拟)

A frog lives on the axis Ox and needs to reach home which is in the point n. She starts from the point 1. The frog can jump to the right at a distance not more than d. So, after she jumped from the po...

码农的一亩三分地 1100

Gephi新手必看:如何用Excel整理CSV数据快速生成网络图(附模板)

本文为Gephi新手提供了一份从Excel数据整理到生成专业网络图的完整指南。详细讲解了如何构建规范的节点表和边表CSV文件,并导入Gephi进行可视化分析。通过实战案例,帮助读者快速掌握利用Excel整理数据、规避常见错误,并运用布局算法与视觉编码,将复杂关系数据转化为直观的网络洞察。

weixin_28487433的博客 389

告别代码恐惧!用KRobot图形化编程,10分钟搞定Arduino巡线小车(附完整接线图)

本文介绍如何使用KRobot图形化编程工具快速搭建Arduino巡线小车,无需编写代码。从硬件准备到逻辑构建,详细讲解传感器数据处理、电机控制优化及高级功能扩展,帮助教育工作者和创客爱好者10分钟内完成项目。

weixin_30632089的博客 393

The Way to Home(动态规划,模拟)

A frog lives on the axis Ox and needs to reach home which is in the point n. She starts from the point 1. The frog can jump to the right at a distance not more than d. So, after she jumped from the po...

qq_43811879的博客 1227

基于eBPF的零侵入LLM智能体观测:AgentSight架构与实战

在分布式系统和云原生架构中,可观测性是保障应用稳定运行与高效排障的核心能力。其原理在于通过日志、指标和追踪三大支柱,从外部视角持续收集和分析系统状态,而非依赖应用内部埋点。这一技术价值在于能以统一、低开销的方式,理解复杂系统的内部行为,尤其在微服务、容器化及Serverless等动态环境中至关重要。应用场景广泛覆盖了性能监控、安全审计、故障诊断与根因分析。当我们将这一基础理念应用于当下快速发展的AI智能体领域时,便自然引出了对LLM智能体进行无侵入、系统级行为观测的需求。传统的应用层方案需要集成SDK,对闭

weixin_28696185的博客 322

Codeforces Testing Round #14 (Unrated) A - The Way to Home

贪心,从现在的位置+d开始搜索’1’,如果搜索到了就跳上去,如果没搜索到就失败,如果最后跳到了,就成功,输出跳的次数#include <iostream> #include <string> #define min(_x,_y) ((_x<_y)?(_x):(_y)) using namespace std; string lilies; int main(){ int now=0,j,n,

Myriad Dreamin 愿逐将属于我的奇迹 376

<PLC><西门子><工控>西门子博图V18中使用SCL语言编写一个CRC16-modbus校验程序

西门子官方对于SCL语言的介绍如下:SCL 编程语言SCL 编程语言SCL(Structured Control Language,结构化控制语言)是一种基于 PASCAL 的高级编程语言。这种语言基于标准DIN EN 61131-3(国际标准为 IEC 1131-3)。根据该标准,可对用于可编程逻辑控制器的编程语言进行标准化。SCL 编程语言实现了该标准中定义的 ST 语言 (结构化文本) 的PLCopen 初级水平。语言元素。

用沸腾的热血,支付我们的人生吧! 1435

Qt版Dalsa线扫相机的采集Demo

Qt Dalsa

追赶时代的博客 604

DP基础练习1

题面: 有一楼梯共M级,刚开始时你在第一级,若每次只能跨上一级或二级,要走上第M级,共有多少种走法? Input 输入数据首先包含一个整数N,表示测试实例的个数,然后是N行数据,每行包含一个整数M(1<=M<=40),表示楼梯的级数。 Output 对于每个测试实例,请输出不同走法的数量 Sample Input 2 2 3 Sample Output 1 2 ...

CHL的博客 557

python-pandapower电力系统潮流计算(算例8:ieee33节点潮流计算))

python-pandapower电力系统潮流计算(算例8:ieee33节点潮流计算))

总裁余(余登武)博客 5031

[Xcode] The iPhone simulator do not have home button

By default, there is no home key inside the simulator. So we cannot close the application and go to the home screen.There is another way to implement this action. Use below group keys: shift + command

JasonYao的程序猿路 944

使用Verilog实现QR分解——嵌入式 [设计与代码]

通过Verilog的硬件描述语言,我们可以将QR分解算法实现为硬件电路,并在嵌入式系统中高效地运行。本文将介绍如何使用Verilog设计并实现QR分解算法,该算法用于将一个矩阵分解为正交矩阵Q和上三角矩阵R。具体而言,QR分解通过对矩阵的列进行正交化处理,得到正交矩阵Q,并将对应的正交化结果存储在上三角矩阵R中。该算法通过将矩阵分解为两个部分,正交矩阵Q和上三角矩阵R,实现了对矩阵的分解和变换。模块,该模块接收待分解矩阵A,并输出正交矩阵Q和上三角矩阵R。下面给出了使用Verilog实现QR分解的源代码。

CodeMaven的博客 620

Seurat-SCTransform与harmony整合学习

源于R tips:Seurat之SCTransform方法原理 (qq.com)Seurat对象在经过SCTransform处理后会增加一个SCT的Assay,里面的scaled.data就是经过scale之后的pearson residual值,这个值是用于后续降维聚类分析使用的。

hx2024的博客 2330

ugll_java_home,React Native:未设置JAVA_HOME并且在您的PATH中找不到'java'命令

I've followed step by step the official Getting Started. I started from a clean linux install and installed everything required as per the "Building Projects with Native Code" tab. I have also read th...

weixin_34710938的博客 542

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

fakecloud贡献新服务指南:从提交Smithy模型到100%一致的AWS服务,10步完整流程

fakecloud 是一个免费开源的本地 AWS 模拟器(LocalStack 的替代品),已实现 107 个服务、7,657 个操作,并达到 100% Smithy 一致性。本文面向想贡献新 AWS 服务的开发者,完整拆解从提交 Smithy 模型、创建服务 crate、实现操作处理,到运行一致性探针(conformance probe)直至 100% 通过的 10 步流程,帮你一次性通过 CI

gitblog_00086的博客 523

怀旧版电脑GBC模拟器

再现原版GBC掌机的界面,电脑运行连游戏界面都一样大小,很怀旧,很真实,(英文版)强烈推荐,很小的文件,很难才找到的。

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

历史模拟与蒙特卡洛模拟_在PHP中运行蒙特卡洛模拟

历史模拟与蒙特卡洛模拟One of the exciting things in the 1980’s was programming simulations to solve complex analytical problems, and one of the most useful techniques employed was running Monte Carlo simulations...

culi4814的博客 832

廖雪峰Python教程[完整版]

廖雪峰的python教程整理的,已经排好版了,而且还是完整的,适合小白

hdu 1200 To and Fro(简单模拟或DP)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1200 To and Fro Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 5129    Accepted Submission(s):

若忆_star 482

Find a way HDU - 2612 (BFS + 模拟)

Find a way Problem Description Pass a year learning in Hangzhou, yifenfei arrival hometown Ningbo at finally. Leave Ningbo one year, ...

forever_131514的博客 331

Spring Outing————模拟

文章目录1 题目2 解析2.1 题意2.2 思路3 参考代码 1 题目 Spring Outing 时间限制 1000 ms 内存限制 32768 KB 代码长度限制 100 KB 判断程序 Standard (来自 小小) 题目描述 You class are planning for a spring outing. N people are voting for a destination...

韩江雪de 小屋 818

疫情模拟——城市地点及路径设置

总体思路 疫情的模拟除了有人,我们还希望将“人”置于一个更加真实的环境中,使人在疫情中的行为更加“合理”。于是我们构建了若干个虚拟的“城市”,城市中有各种建筑,有道路。在保证我们需要的城市功能完整的情况下,为了降低城市的复杂度,我们在每个城市中设置了home(住宅)、market(菜场)、workplace(工作场所)、hospital(医院)、station(高铁站)、cross(路口)六种地标...

weixin_43841085的博客 745

HDOJ 1200 To and Fro(简单模拟)

To and Fro Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 5473    Accepted Submission(s): 3785 Problem Description Mo and Larry

Chunzhen的博客 702

HDU 5500 - Reorder the Books(模拟)

Reorder the BooksTime Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 1432 Accepted Submission(s): 755Problem Description dxy has a collection

Snakeflute的博客 329
上一篇: Burn the Linked Camp ZOJ - 2770(差分约束系统)
下一篇: Bi-shoe and Phi-shoe LightOJ - 1370(筛素数,欧拉函数)
Guuuuuu老师儿
博客等级 码龄9年 259粉丝 718原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值