21天好习惯第一期-12【每日一题】过河

[NOIP2005]过河
、Question:

青蛙从桥头跳过独木桥,跳过就行,桥长为ll ,青蛙跳过的路程disdis 只要大于等于ll 就行。桥上有一些石头,题目会给石头的数量m和m个石头的位置,还有青蛙跳跃的最小距离s、最大距离t。
在这里插入图片描述

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e4+5;
template <class T>
inline void read(T &res) {
    char c; T flag = 1;
    while ((c = getchar()) < '0' || c > '9')
        if (c == '-')
            flag = -1;
    res = c - '0';
    while ((c = getchar()) >= '0' && c <= '9')
        res = res * 10 + c - '0';
    res *= flag;
}
int dis[105],a[105],stone[maxn],f[maxn],p;//局部变量的值都是0 
int main() {
    int l,s,t,m;
    read(l);
    read(s),read(t),read(m);
    if(s==t) {
        int pos,cnt=0;
        for(int i=1;i<=m;++i){
            read(pos);
            cnt+=(pos%s==0);
        }
        printf("%d\n",cnt);
        return 0;
    }
    for(int i=1;i<=m;++i)    read(a[i]);
    sort(a+1,a+1+m);
    for(int i=1;i<=m;++i) {
        dis[i]=min(a[i]-a[i-1],90);//a[0]等于0,也就是起点 
        p+=dis[i];
        stone[p]=1;
    }
    dis[m+1]=min(l-a[m],90);
    p+=dis[m+1];
    for(int i=1;i<=p+9;++i) {
        f[i]=0x3f3f3f3f;
        for(int j=s;j<=t;++j) if(i>=j)
        f[i]=min(f[i],f[i-j]+stone[i]);
    }
    int ans=0x3f3f3f3f;
    for(int i=p;i<=p+9;++i) ans=min(ans,f[i]);
    printf("%d\n",ans);
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值