Luogu3403: 跳楼机
2024-08-22 19:19:29
题面
Sol
有一个显然的想法
处理出\(y, z\)能凑出的高度
然后这些高度凑一些\(x\)就可以得到其它的高度
那么可以把这些\(y, z\)凑出的高度对\(x\)取模,其它的用\(x\)来填补
所以设\(f[i]\)表示\(y, z\)凑出高度\(\%x\)为\(i\)需要的最低高度
那么答案就是
\[\sum_{i=0}^{x-1}\lfloor\frac{(n-f[i])}{x}\rfloor+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;
}
最新文章
- Xamarin+Prism小试牛刀:定制跨平台Outlook邮箱应用(后续)
- XStream学习笔记
- 自己写的一个简单的jQuery提示插件
- Android几种打开SQLite的方法
- CSS3中的animation动画
- <;<;卸甲笔记>;>;-Oracle线下迁移到PPAS
- HTML5和css3的总结
- wordpress 提取头像的src
- Http协议与TCP协议理解
- 安卓Eclipse开发者的福音
- .Net中World转PDF
- 算法: 包含min函数的栈
- 优化CSS重排重绘与浏览器性能
- Scrapy基础02
- Ubuntu18系统qt生成程序无法双击运行问题
- Python 进行查询日志查询条件分析
- 第15月第22天 libz.dylib
- jsp中的include静态包含与动态包含,
- JavaScript计算指定日期与当前日期的相差天数
- Touchmove获取当前触摸的Dom节点