题目
题目描述
In one one-dimensional world there are nn platforms. Platform with index kk (platforms are numbered from 1) is a segment with coordinates [(k-1)m,(k-1)m+l][(k−1)m,(k−1)m+l] , and l<ml<m . Grasshopper Bob starts to jump along the platforms from point 00 , with each jump he moves exactly dd units right. Find out the coordinate of the point, where Bob will fall down. The grasshopper falls down, if he finds himself not on the platform, but if he finds himself on the edge of the platform, he doesn't fall down.
输入格式
The first input line contains 4 integer numbers nn , dd , mm , ll ( 1<=n,d,m,l<=10^{6},l<m1<=n,d,m,l<=106,l<m ) — respectively: amount of platforms, length of the grasshopper Bob's jump, and numbers mm and ll needed to find coordinates of the kk -th platform: [(k-1)m,(k-1)m+l][(k−1)m,(k−1)m+l] .
输出格式
Output the coordinates of the point, where the grosshopper will fall down. Don't forget that if Bob finds himself on the platform edge, he doesn't fall down.
题意翻译
题目描述:在一坐标轴上给出n块板子,每个板子所占的空间为[(k-1)m,(k-1)m+l](l<m),一个青蛙从原点0起跳,每次跳d距离远,问最后青蛙会落在哪里(没落在板子上就结束跳跃) 输入:一行四个整数n,d,m,l 输出:一个整数,即青蛙最后的落点 1<=n,d,m,l<=10^6 l<m
Translated by 稀神探女
输入输出样例
输入 #1复制
2 2 5 3
输出 #1复制
4
输入 #2复制
5 4 11 8
输出 #2复制
20
思路
其实这题,关键是要看懂题目。
简单来说就是,从原点起跳,每次跳的距离为d,跳到没有板子的地方就停止了。有n块板子,每块板子一样长,长度为l,板子和板子之间有间隙,题目中的k其实是板子的编号,从1到n。那么板子与板子之间的距离其实就是(m-l)。
大概就是图画的那样
代码展示
题目看懂了那么题目就很好写了
#include<stdio.h>
long long int n,d,m,l,i,sum;
int main()
{
scanf("%lld%lld%lld%lld",&n,&d,&m,&l);
for(i=1;i<=n;i++)
{
if(sum<((i-1)*m))//跳不上板子了
break;
while(sum<=(i-1)*m+l)//跳的上板子,直到跳出板子
sum=(((i-1)*m+l)/d)*d+d;
}
printf("%lld",sum);
return 0;
}