AtCoder Beginner Contest 084 C - 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
- 3
- 6 5 1
- 1 10 1
Sample Output 1 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
- 4
- 12 24 6
- 52 16 4
- 99 2 2
Sample Output 2 Copy
- 187
- 167
- 101
- 0
Sample Input 3 Copy
- 4
- 12 13 1
- 44 17 17
- 66 4096 64
Sample Output 3 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的更多相关文章
- AtCoder Beginner Contest 084(AB)
A - New Year 题目链接:https://abc084.contest.atcoder.jp/tasks/abc084_a Time limit : 2sec / Memory limit ...
- AtCoder Beginner Contest 084 D - 2017-like Number【数论/素数/前缀和】
D - 2017-like Number Time limit : 2sec / Memory limit : 256MB Score : 400 points Problem Statement W ...
- AtCoder Beginner Contest 100 2018/06/16
A - Happy Birthday! Time limit : 2sec / Memory limit : 1000MB Score: 100 points Problem Statement E8 ...
- AtCoder Beginner Contest 052
没看到Beginner,然后就做啊做,发现A,B太简单了...然后想想做完算了..没想到C卡了一下,然后还是做出来了.D的话瞎想了一下,然后感觉也没问题.假装all kill.2333 AtCoder ...
- AtCoder Beginner Contest 053 ABCD题
A - ABC/ARC Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Smeke has ...
- AtCoder Beginner Contest 136
AtCoder Beginner Contest 136 题目链接 A - +-x 直接取\(max\)即可. Code #include <bits/stdc++.h> using na ...
- AtCoder Beginner Contest 137 F
AtCoder Beginner Contest 137 F 数论鬼题(虽然不算特别数论) 希望你在浏览这篇题解前已经知道了费马小定理 利用用费马小定理构造函数\(g(x)=(x-i)^{P-1}\) ...
- AtCoder Beginner Contest 076
A - Rating Goal Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Takaha ...
- AtCoder Beginner Contest 079 D - Wall【Warshall Floyd algorithm】
AtCoder Beginner Contest 079 D - Wall Warshall Floyd 最短路....先枚举 k #include<iostream> #include& ...
随机推荐
- 利用GitHub来进行团队协作开发项目
首先: 1.项目组长要在GitHub创建一个仓库 2.组长git clone仓库地址到本地 3.组长在本地克隆到的项目里面创建一个Django项目 4.在当前项目下进行git add以及git ...
- PHP实现定时任务(非linux-shell方式,与操作系统无关)
页面交互效果 下面是写好的示例前端交互页面,主要是列表页面,编辑页面. 主要交互有: 1 开启定时任务进程 2 关闭定时任务进程 3 新增一项定时任务 4 编辑已有的定时任务 5 删除定时任务 6 开 ...
- Leetcode443.String Compression压缩字符串
给定一组字符,使用原地算法将其压缩. 压缩后的长度必须始终小于或等于原数组长度. 数组的每个元素应该是长度为1 的字符(不是 int 整数类型). 在完成原地修改输入数组后,返回数组的新长度. 进阶: ...
- 通过游戏学python 3.6 第一季 第七章 实例项目 猜数字游戏--核心代码--猜测次数--随机函数和屏蔽错误代码--优化代码及注释--简单账号密码登陆--账号的注册查询和密码的找回修改--锁定账号
#猜数字--核心代码--猜测次数--随机函数和屏蔽错误代码---优化代码及注释--简单账号密码登陆--账号的注册查询和密码的找回修改--锁定账号 #猜数字--核心代码--猜测次数--随机函数和屏蔽错误 ...
- TZ_11_Spring-Boot的整合SpringMvc和MyBatis
1.整合SpringMVC 虽然默认配置已经可以使用SpringMVC了,不过我们有时候需要进行自定义配置. 1>修改方式 通过application.yaml 此名字不需要使用@Propert ...
- H5C3--transform实现任何元素居中对齐
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Web App开发注意事项
1.首先我们来看看webkit内核中的一些私有的meta标签,这些meta标签在开发webapp时起到非常重要的作用 <meta content=”width=device-width, ini ...
- web前端学习(四)JavaScript学习笔记部分(8)-- JavaScript 浏览器对象
1.window对象 1.1.window对象: window对象是BOM的核心,window对象指当前的浏览器窗口 所有javaScript全局对象.函数以及变量均自动生成为window对象的成员 ...
- 直接在安装了redis的Linux机器上操作redis数据存储类型--对Sorted-Sets操作
一.概述: Sorted-Sets和Sets类型极为相似,它们都是字符串的集合,都不允许重复的成员出现在一个Set中.它们之间的主要差别是Sorted-Sets中的每一个成员都会有一个分数(score ...
- 2018-2-13-C#-相对路径转绝对路径
title author date CreateTime categories C# 相对路径转绝对路径 lindexi 2018-2-13 17:23:3 +0800 2018-2-13 17:23 ...