博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
AtCoder Beginner Contest 084 C - Special Trains
阅读量:6540 次
发布时间:2019-06-24

本文共 2819 字,大约阅读时间需要 9 分钟。

Problem Statement

A railroad running from west to east in Atcoder Kingdom is now complete.

There are NN stations on the railroad, numbered 11 through NN from west to east.

Tomorrow, the opening ceremony of the railroad will take place.

On this railroad, for each integer ii such that 1iN11≤i≤N−1 , there will be trains that run from Station ii to Station i+1i+1 in CiCi seconds. No other trains will be operated.

The first train from Station ii to Station i+1i+1 will depart Station ii SiSi seconds after the ceremony begins. Thereafter, there will be a train that departs Station ii every FiFi seconds.

Here, it is guaranteed that FiFi divides SiSi .

That is, for each Time tt satisfying SitSi≤t and tFi=0t%Fi=0 , there will be a train that departs Station ii tt seconds after the ceremony begins and arrives at Station i+1i+1 t+Cit+Ci seconds after the ceremony begins, where ABA%B denotes AA modulo BB , and there will be no other trains.

For each ii , find the earliest possible time we can reach Station NN if we are at Station ii when the ceremony begins, ignoring the time needed to change trains.

Constraints

  • 1N5001≤N≤500
  • 1Ci1001≤Ci≤100
  • 1Si1051≤Si≤105
  • 1Fi101≤Fi≤10
  • SiFi=0Si%Fi=0
  • All input values are integers.

Input

Input is given from Standard Input in the following format:

NN C1C1  S1S1  F1F1 :: CN−1CN−1  SN−1SN−1  FN−1FN−1

Output

Print NN lines. Assuming that we are at Station ii (1iN)(1≤i≤N) when the ceremony begins, if the earliest possible time we can reach Station NN is xx seconds after the ceremony begins, the ii -th line should contain xx .


Sample Input 1 Copy

Copy
36 5 11 10 1

Sample Output 1 Copy

Copy
12110

We will travel from Station 11 as follows:

  • 55 seconds after the beginning: take the train to Station 22 .
  • 1111 seconds: arrive at Station 22 .
  • 1111 seconds: take the train to Station 33 .
  • 1212 seconds: arrive at Station 33 .

We will travel from Station 22 as follows:

  • 1010 seconds: take the train to Station 33 .
  • 1111 seconds: arrive at Station 33 .

Note that we should print 00 for Station 33 .


Sample Input 2 Copy

Copy
412 24 652 16 499 2 2

Sample Output 2 Copy

Copy
1871671010

Sample Input 3 Copy

Copy
412 13 144 17 1766 4096 64

Sample Output 3 Copy

Copy
4162416241620

Fisrt,considering when it is possible to ride a train which goes to station j+1 ,in the situation that arriving station j ,t seconds after the ceremony begin.

・If t < Sj , Sj seconds after the ceremony begin.

・If t ≧ Sj ,but t % Fj = 0 , t seconds after the ceremony begin.

・Othersise, t + Fj −(t % Fj) seconds after the ceremony begin. Considering this,simulate in every case,it would be O(N2) and you can get 300 points.、

 

1 #include 
2 int N,C[500],S[500],F[500]; 3 int main() 4 { 5 scanf("%d",&N); 6 for(int i=0; i

 

 

转载于:https://www.cnblogs.com/zxhyxiao/p/8151308.html

你可能感兴趣的文章
taobao
查看>>
Dijkstra算法的C语言程序
查看>>
HDU4706 Children's Day
查看>>
实验五感想
查看>>
简单练习题
查看>>
iOS网络编程笔记——GCDAsyncSocket使用
查看>>
数据库MySQL基本语法思维导图
查看>>
如何用PyQt5写个通讯录
查看>>
git命令总结
查看>>
Django框架中,使用celery实现异步
查看>>
数据结构c语言
查看>>
Map集合
查看>>
Could not load file or assembly 'System.Web.Extensions
查看>>
图的遍历——BFS(队列实现)
查看>>
yum仓库
查看>>
远程控制卡配置和RAID基本知识
查看>>
可扩展多线程异步Socket服务器框架EMTASS 2.0 (转自:http://blog.csdn.net/hulihui)
查看>>
epoll讲解
查看>>
轻松理解—继承成员访问控制机制
查看>>
dubbo源码解析一
查看>>