Special Trains

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 1≤i≤N−11≤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 Si≤tSi≤t and t%Fi=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 A%BA%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

  • 1≤N≤5001≤N≤500
  • 1≤Ci≤1001≤Ci≤100
  • 1≤Si≤1051≤Si≤105
  • 1≤Fi≤101≤Fi≤10
  • Si%Fi=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 (1≤i≤N)(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
3
6 5 1
1 10 1

Sample Output 1 Copy

Copy
12
11
0

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
4
12 24 6
52 16 4
99 2 2

Sample Output 2 Copy

Copy
187
167
101
0

Sample Input 3 Copy

Copy
4
12 13 1
44 17 17
66 4096 64

Sample Output 3 Copy

Copy
4162
4162
4162
0

https://img.atcoder.jp/abc084/editorial.pdf

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.、

 #include <cstdio >
int N,C[],S[],F[];
int main()
{
scanf("%d",&N);
for(int i=; i<N-; i++)
scanf("%d%d%d",&C[i],&S[i],&F[i]);
for(int i=; i<N; i++)
{
int t=;
for(int j=i; j<N-; j++)
{
i
f(t<S[j])t=S[j];
else if(t%F[j]==);
else t=t+F[j]-t%F[j];
t+=C[j];
}
printf("%d\n",t);
}
}

AtCoder Beginner Contest 084 C - Special Trains的更多相关文章

  1. AtCoder Beginner Contest 084(AB)

    A - New Year 题目链接:https://abc084.contest.atcoder.jp/tasks/abc084_a Time limit : 2sec / Memory limit  ...

  2. AtCoder Beginner Contest 084 D - 2017-like Number【数论/素数/前缀和】

    D - 2017-like Number Time limit : 2sec / Memory limit : 256MB Score : 400 points Problem Statement W ...

  3. AtCoder Beginner Contest 100 2018/06/16

    A - Happy Birthday! Time limit : 2sec / Memory limit : 1000MB Score: 100 points Problem Statement E8 ...

  4. AtCoder Beginner Contest 052

    没看到Beginner,然后就做啊做,发现A,B太简单了...然后想想做完算了..没想到C卡了一下,然后还是做出来了.D的话瞎想了一下,然后感觉也没问题.假装all kill.2333 AtCoder ...

  5. AtCoder Beginner Contest 053 ABCD题

    A - ABC/ARC Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Smeke has ...

  6. AtCoder Beginner Contest 136

    AtCoder Beginner Contest 136 题目链接 A - +-x 直接取\(max\)即可. Code #include <bits/stdc++.h> using na ...

  7. AtCoder Beginner Contest 137 F

    AtCoder Beginner Contest 137 F 数论鬼题(虽然不算特别数论) 希望你在浏览这篇题解前已经知道了费马小定理 利用用费马小定理构造函数\(g(x)=(x-i)^{P-1}\) ...

  8. AtCoder Beginner Contest 076

    A - Rating Goal Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Takaha ...

  9. AtCoder Beginner Contest 079 D - Wall【Warshall Floyd algorithm】

    AtCoder Beginner Contest 079 D - Wall Warshall Floyd 最短路....先枚举 k #include<iostream> #include& ...

随机推荐

  1. IO流15 --- 数据流操作Java语言的基本数据类型 --- 技术搬运工(尚硅谷)

    写入数据 @Test public void test10() throws IOException { DataOutputStream dos = new DataOutputStream(new ...

  2. Java爬虫的实现

    距离上一次写爬虫还是几年前了,那时候一直使用的是httpclient. 由于最近的项目又需要使用到爬虫,因此又重新查询了一些爬虫相关的框架,其中最合适的是WebMagic 官方文档:https://g ...

  3. Luogu P2292 [HNOI2004]L语言(Trie+dp)

    P2292 [HNOI2004]L语言 题面 题目描述 标点符号的出现晚于文字的出现,所以以前的语言都是没有标点的.现在你要处理的就是一段没有标点的文章. 一段文章 \(T\) 是由若干小写字母构成. ...

  4. 批量操作文本文件进行dos/unix格式转换

    批量将目录下所有文件进行 dos/unix 格式转换 使用 sed + grep #sed -i "s/原字符串/新字符串/g" `grep 原字符串 -rl 所在目录` eg:  ...

  5. bzoj 1800 [Ahoi2009]fly 飞行棋——模拟

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1800 原来只想到一个弧是一条边. 然后发现不是.差点不会做.经Zinn提醒,不用枚举那条边由 ...

  6. java实体类的属性名首字母不能大写,不然el表达式无法取值

    摘要:Java命名规范中,实体类属性名以小写字母开头,但并没有说不能以大写字母开头,然而事实告诉我,大写真不行 https://www.cnblogs.com/jnhs/p/10025757.html

  7. springmvc配置不拦截静态资源

    <mvc:resources mapping="/js/**" location="/js/"/>

  8. 洛谷P1832 A+B Problem(再升级) [2017年4月计划 动态规划03]

    P1832 A+B Problem(再升级) 题目背景 ·题目名称是吸引你点进来的 ·实际上该题还是很水的 题目描述 ·1+1=? 显然是2 ·a+b=? 1001回看不谢 ·哥德巴赫猜想 似乎已呈泛 ...

  9. 怎么让一个不定宽高的div垂直水平居中?

    方法一:使用CSS3 transform 父盒子设置:position:relative; div设置:position:absolute;transform:translate(-50%,-50%) ...

  10. 模拟19 题解(waiting)

    T1,千万别转化成链了!! 直接数就可以,dfs搜索每种情况,对于搜到的点,如果子树大小过大,直接return,相等说明可以,小的话向上累加, 优化是先预处理子树大小,若子树小,不用搜了直接加上就行 ...