http://poj.org/problem?id=3539

给定一个电梯,可以上升a,b,c层和回到1层,给定楼高h,求可达层数

lyd讲的同余类BFS,方法是先把三个量压成两个,即把h%a,因为对于一个x∈{h%a},若x可达,则x+ak一定可达。

然后考虑在这个模a的剩余系中,b和c的情况。

从1开始连边,从点i连向(i+w)%a,代价为w,其中w为b或c。

意义就是,对于一个楼层x,从x到达最近x+w层的代价为w,这很显然。

从1开始做单源最短路,然后只需要统计dis小于等于h的,大于的显然不可达了。

因为是在模a剩余系下做的,所以对于一个满足dis[u]<=h的u,它是一个剩余系的代表元,要算出剩余系大小。

//drunk,fix later
#include<iostream>
#include<cstring>
#include<cstdio>
#include<queue> using namespace std; typedef long long ll; const int MAXN=; struct Edge{
int next,to;
ll w;
}e[MAXN<<];
int ecnt,head[MAXN];
inline void add(int x,int y,ll w){
e[++ecnt].next = head[x];
e[ecnt].to = y;
e[ecnt].w = w;
head[x] = ecnt;
} ll h,a,b,c; queue<int> Q;
int inq[MAXN];
ll dis[MAXN];
void spfa(){
for(int i=;i<=a;i++) dis[i]=1ll<<;
Q.push();inq[]=;dis[]=;
while(!Q.empty()){
int top=Q.front();Q.pop();inq[top]=;
for(int i=head[top];i;i=e[i].next){
int v=e[i].to;
if(dis[v]>dis[top]+e[i].w){
dis[v]=dis[top]+e[i].w;
if(!inq[v]) Q.push(v),inq[v]=;
}
}
}
} int main(){
cin>>h>>a>>b>>c;
if(a>b) swap(a,b);
if(a>c) swap(a,c);
if(a==) return cout<<h,;
for(int i=;i<a;i++){
add(i,(i+b)%a,b);
add(i,(i+c)%a,c);
}
ll sum=;
spfa();
for(int i=;i<a;i++) if(dis[i]<=h) sum+=(ll)(h-dis[i])/a+;
cout<<sum;
return ;
}

[POJ] 3539 Elevator的更多相关文章

  1. poj 3539 Elevator——同余类bfs

    题目:http://poj.org/problem?id=3539 考虑把层数分为模a剩余系.同类内可通过+若干个a走到. 不同类之间需要通过+b.+c来走到. 需要求出每一类中最小的能走到的.即最短 ...

  2. [poj 3539] Elevator (同余类bfs)

    Description Edward works as an engineer for Non-trivial Elevators: Engineering, Research and Constru ...

  3. POJ 3539 Elevator(同余类BFS)

    题意 有一部电梯,最初停在1层. 电梯有4个按键,上升a,b,c层,回到一层. 求从一层出发.能到达1~h的哪些楼层. (h<=1018,a,b,c<=105) 题解 这种h能大的图论,一 ...

  4. HDU 2494/POJ 3930 Elevator(模拟)(2008 Asia Regional Beijing)

    Description Too worrying about the house price bubble, poor Mike sold his house and rent an apartmen ...

  5. poj 2392 Space Elevator(多重背包+先排序)

    Description The cows are going to space! They plan to achieve orbit by building a sort of space elev ...

  6. POJ 2392 Space Elevator(贪心+多重背包)

    POJ 2392 Space Elevator(贪心+多重背包) http://poj.org/problem?id=2392 题意: 题意:给定n种积木.每种积木都有一个高度h[i],一个数量num ...

  7. poj[2392]space elevator

    Description The cows are going to space! They plan to achieve orbit by building a sort of space elev ...

  8. POJ 2392 Space Elevator DP

    该题与POJ 1742的思路基本一致:http://www.cnblogs.com/sevenun/p/5442279.html(多重背包) 题意:给你n个电梯,第i个电梯高h[i],数量有c[i]个 ...

  9. POJ 2392 Space Elevator(多重背包变形)

    Q: 额外添加了最大高度限制, 需要根据 alt 对数据进行预处理么? A: 是的, 需要根据 alt 对数组排序 Description The cows are going to space! T ...

随机推荐

  1. Thirft 客户端等待时间

    thrift框架使用C++ thrift shows CLOSE_WAIL error thrift中TNonblockingServer的简单用法

  2. Cg(c for graphic)语言的数据类(转)

    抄“GPU Programming And Cg Language Primer 1rd Edition” 中文名“GPU编程与CG语言之阳春白雪下里巴人” 本章将着重介绍Cg语言中预定义的内置(bu ...

  3. IEnumerable<T> 的时候一个主意事项p

    IEnumerator IEnumerable.GetEnumerator() { return _vtDataView.GetEnumerator(); } public IEnumerator&l ...

  4. 浅谈算法——FWT(快速沃尔什变换)

    其实FWT我啥都不会,反正就是记一波结论,记住就好-- 具体证明的话,推荐博客:FWT快速沃尔什变换学习笔记 现有一些卷积,形如 \(C_k=\sum\limits_{i\lor j=k}A_i*B_ ...

  5. CodeForces - 816C Karen and Game(简单模拟)

    Problem Description On the way to school, Karen became fixated on the puzzle game on her phone! The ...

  6. Suricata的初始化脚本

    见官网 https://suricata.readthedocs.io/en/latest/initscripts.html

  7. props.children 和容器类组件

    有一类组件,充当了容器的作用,它定义了一种外层结构形式,然后你可以往里面塞任意的内容.这种结构在实际当中非常常见,例如这种带卡片组件: 组件本身是一个不带任何内容的方形的容器,我可以在用这个组件的时候 ...

  8. 刷ID卡的就餐系统

    需求分析:公司旧的考勤系统,缺 “就餐”功能模块,不能查询和统计每天的就餐人数.故需开发一个简易的“刷ID卡的就餐系统”,三 部 分组成,一部分为人事资料的增删改查,二部分为处理从“刷卡就餐机”采集的 ...

  9. servlet上传文件+上传进度显示

    效果图 功能描述 1.使用jquery.form.js实现异步上传功能,并显示上传进度 2.servlet中保存上传的文件到指定文件夹 3.查看已经上传的文件 4.不同文件类型用不同图标显示 下载 h ...

  10. AJPFX总结java开发常用类(包装,数字处理集合等)(二)

    二:进军集合类 集合其实就是存放对象的容器,专业点说就是集合是用来存储和管理其他对象的对象,即对象的容器.集合可以扩容,长度可变,可以存储多种类型的数据,而数组长度不可变,只能存储单一类型的元素 用一 ...