E - Elevator
http://codeforces.com/gym/241680/problem/E
同余最短路,从0~a-1中每一个i向(i+b)%a连一条权值为b的边,向(i+c)%a连一条权值为c的边,然后跑spfa最短路,此时d[i]表示达到x%a花费的最小的距离,这里放的只有b,c,(解释一下,b,c组合出的实际大小为x,因为x过大,数组存不下,所以表示为x%a
最后统计答案的时候ans+=1+(h-d[i])/a;当前只有b,c组合出的d[i]算一个答案,然后剩下可以用a来填充

//用最小的来做同余系比较快

 #include<iostream>
#include<cstdio>
#include<queue>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<set>
#include<map>
#include<stack>
#include<cstring>
#define inf 2147483647
#define INF 9187201950435737471
#define ls rt<<1
#define rs rt<<1|1
#define lson ls,nl,mid,l,r
#define rson rs,mid+1,nr,l,r
#define N 100010
#define For(i,a,b) for(long long i=a;i<=b;i++)
#define p(a) putchar(a)
#define g() getchar() using namespace std;
long long h;
long long a,b,c,ans;
long long d[];
queue<long long>q;
bool vis[]; struct node{
long long v;
long long n;
node *next;
}*e[]; void in(long long &x){
long long y=;
char c=g();x=;
while(c<''||c>''){
if(c=='-')y=-;
c=g();
}
while(c<=''&&c>=''){
x=(x<<)+(x<<)+c-'';c=g();
}
x*=y;
}
void o(long long x){
if(x<){
p('-');
x=-x;
}
if(x>)o(x/);
p(x%+'');
} void push(long long x,long long y,long long v){
node *p;
p=new node();
p->n=y;
p->v=v;
if(e[x]==)
e[x]=p;
else{
p->next=e[x]->next;
e[x]->next=p;
}
} void spfa(){
For(i,,a)
d[i]=INF;
q.push(%a);
d[%a]=;
while(!q.empty()){
long long t=q.front();
q.pop();
vis[t]=true; for(node *i=e[t];i;i=i->next){
if(d[i->n]>d[t]+i->v){
d[i->n]=d[t]+i->v;
if(!vis[i->n]){
q.push(i->n);
vis[i->n]=true;
}
}
}
vis[t]=false;
}
} int main(){
freopen("elevator.in","r",stdin);
freopen("elevator.out","w",stdout);
in(h);
in(a);in(b);in(c);
if(a>b) swap(a,b);
if(a>c) swap(a,c);
For(i,,a-){
push(i,(i+b)%a,b);
push(i,(i+c)%a,c);
}
spfa();
For(i,,a-)
if(h>=d[i])
ans+=+(h-d[i])/a;
o(ans);
return ;
}

E - Elevator的更多相关文章

  1. HDOJ 1008. Elevator 简单模拟水题

    Elevator Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Su ...

  2. poj[2392]space elevator

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

  3. Design Elevator

    From: https://discuss.leetcode.com/topic/89/write-elevator-program-using-event-driven-programming/9 ...

  4. PAT (Advanced Level) Practise:1008. Elevator

    [题目链接] The highest building in our city has only one elevator. A request list is made up with N posi ...

  5. Pair Project: Elevator Scheduler [电梯调度算法的实现和测试]

    作业提交时间:10月9日上课前. Design and implement an Elevator Scheduler to aim for both correctness and performa ...

  6. POJ2392Space Elevator(贪心+背包)

    Space Elevator Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9970   Accepted: 4738 De ...

  7. hdu 1008 Elevator

    Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Description The hig ...

  8. 【ACM】HDU1008 Elevator 新手题前后不同的代码版本

    [前言] 很久没有纯粹的写写小代码,偶然想起要回炉再来,就去HDU随便选了个最基础的题,也不记得曾经AC过:最后吃惊的发现,思路完全不一样了,代码风格啥的也有不小的变化.希望是成长了一点点吧.后面定期 ...

  9. Elevator 分类: HDU 2015-06-19 21:52 13人阅读 评论(0) 收藏

    Elevator Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Subm ...

  10. 1008. Elevator (20)

    The highest building in our city has only one elevator. A request list is made up with N positive nu ...

随机推荐

  1. Python 条件、循环、异常处理

    一.条件语句 1.布尔值 条件语句中,判断条件的值一般是布尔值.即条件为真时,将执行什么,条件为假时,将执行什么. 下面的值在作为布尔表达式的时候,会被解释器看做假(false): False    ...

  2. 浅谈 JSP & Servlet

    body { text-align: center; } div.develon { background-color: #cccccc; font-size: 20px; } 背景 相信大家都见过这 ...

  3. IIS 常用命令

    Ø  简介 本文主要介绍 IIS 常用的命令,主要包含以下内容: 1.   IIS  重启方法 2.   站点重启方法 3.   应用程序池重启方法 1.   IIS 重启方法 1)   重启 IIS ...

  4. python的socket解析

    1.实现一对一的进行沟通交流 (1).服务端代码如下: import socket server = socket.socket() server.bind(("localhost" ...

  5. Python——一个简单的进度条的实现

    import math def process_bar(total_work,work_index,length): times = total_work / length # 长度倍数,用来缩放或扩 ...

  6. NPOI 读取excel的时候,时间格式的处理

    excel的时间格式是:CellType.Numeric 要判断时间还需要方法:DateUtil.IsCellDateFormatted(cell)的帮助: 示例代码如下: ICell cell = ...

  7. 「luogu2569」[ZJOI2006] 书架

    「luogu2569」[ZJOI2006]书架 题目大意 给定一个长度为 \(n\) 序列,序列中第 \(i\) 个元素有编号 \(a_i(a_i \in \Z \cap [1,n])\),需要支持五 ...

  8. 嵌入式Linux学习路线

    最近比较忙,对于嵌入式的相关学习一直没有很好的开展.今天也看了不少的嵌入式Linux的学习路线,也和几个工作过的朋友聊了聊,想把之后的学习过程记录下来. 自己以后想从事驱动开发这方面的工作,因为大多数 ...

  9. 使用docker中mysql镜像

    1.拉取mysql镜像 docker pull mysql:5.6 2.运行mysql的镜像生成一个正在运行的容器,可以通过docker contain ls得到容器的id信息 docker run ...

  10. 解决tcp粘包问题

    目录 什么是粘包(演示粘包现象) 解决粘包 实际应用 什么是粘包 首先只有tcp有粘包现象,udp没有粘包 socket收发消息的原理 发送端可以是一K一K地发送数据,而接收端的应用程序可以两K两K地 ...