Luogu3403: 跳楼机

题面

传送门

Sol

有一个显然的想法
处理出 y,z y , z 能凑出的高度
然后这些高度凑一些 x x 就可以得到其它的高度

那么可以把这些y,z凑出的高度对 x x 取模,其它的用x来填补
所以设 f[i] f [ i ] 表示 y,z y , z 凑出高度 %x % x i i 需要的最低高度
那么答案就是

i=0x1(nf[i])x+1

# include <bits/stdc++.h>
# define RG register
# define IL inline
# define Fill(a, b) memset(a, b, sizeof(a))
using namespace std;
const int _(1e5 + 5);
typedef long long ll;

IL ll Input(){
    RG ll x = 0, z = 1; RG char c = getchar();
    for(; c < '0' || c > '9'; c = getchar()) z = c == '-' ? -1 : 1;
    for(; c >= '0' && c <= '9'; c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
    return x * z;
}

int x, y, z, first[_], cnt, vis[_];
ll n, ans, f[_];
struct Edge{
    int to, next, w;
} edge[_ << 1];
queue <int> Q;

IL void Add(RG int u, RG int v, RG int w){
    edge[cnt] = (Edge){v, first[u], w}, first[u] = cnt++;
}

int main(RG int argc, RG char* argv[]){
    n = Input(), x = Input(), y = Input(), z = Input();
    if(y < x) swap(x, y);
    if(z < x) swap(x, z);
    for(RG int i = 0; i < x; ++i) first[i] = -1;
    for(RG int i = 0; i < x; ++i) Add(i, (i + y) % x, y), Add(i, (i + z) % x, z);
    Fill(f, 127), f[1 % x] = 1, vis[1 % x] = 1, Q.push(1 % x);
    while(!Q.empty()){
        RG int u = Q.front(); Q.pop();
        for(RG int e = first[u]; e != -1; e = edge[e].next){
            RG int v = edge[e].to, w = edge[e].w;
            if(f[u] + w < f[v]){
                f[v] = f[u] + w;
                if(!vis[v]) vis[v] = 1, Q.push(v);
            }
        }
        vis[u] = 0;
    }
    for(RG int i = 0; i < x; ++i) if(f[i] <= n) ans += (n - f[i]) / x + 1;
    return printf("%lld\n", ans), 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值