AtCoder Beginner Contest 259 - A - Growth Record
Time Limit: 2 sec / Memory Limit: 1024 MB
Score : points
Problem Statement
Takahashi had his -th birthday, when he was centimeters tall.
Additionally, we know the following facts:
- In each year between Takahashi's birth (-th birthday) and his -th birthday, his height increased by centimeters. More formally, for each , his height increased by centimeters between his -th birthday and his -th birthday.
- Between Takahashi's -th birthday and his -th birthday, his height did not change.
Find Takahashi's height on his -th birthday, in centimeters.
Constraints
- Takahashi was at least centimeter tall at his birth.
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the answer as an integer.
Sample Input 1
1 |
|
Sample Output 1
168
In this sample, Takahashi was centimeters tall on his -th birthday. Also, his height did not change between his -th birthday and -th birthday.
From these facts, we find that he was centimeters tall on his -th birthday, so the answer is .
Sample Input 2
1 |
|
Sample Output 2
1 |
|
In this sample, Takahashi was centimeter tall on his -th birthday and centimeters tall on his -st birthday.
Sample Input 3
1 |
|
Sample Output 3
1 |
|
题目大意
高橋君$N$岁时身高为$T$,在$X$岁之前,每年长$D$厘米。($X\sim N$岁就不长了)
问高橋君$M$岁时多高。
解题思路
题目保证了$X < N$,也就是说现在高橋君的身高就是他的最终身高(已经不长了)
因此,对于询问的$M$,如果$M\geq X$,那么就输出高橋君的最终身高;否则看从$M$到$X$有几年,就说明长了几个$D$,用最终身高减去$X-M$个$D$即可。
AC代码
1 |
|
同步发文于CSDN,原创不易,转载请附上原文链接哦~
Tisfy:https://letmefly.blog.csdn.net/article/details/125699180