码迷,mamicode.com
首页 > 其他好文 > 详细

cf18B Platforms(仔细谨慎题)

时间:2015-03-11 16:38:18      阅读:122      评论:0      收藏:0      [点我收藏+]

标签:

题意:

In one one-dimensional world there are n platforms. Platform with index k (platforms are numbered from 1) is a segment with coordinates[(k - 1)m, (k - 1)m + l], and l < m. Grasshopper Bob starts to jump along the platforms from point 0, with each jump he moves exactlyd 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.

找到第一个FALL DOWN的位置

 

思路:

暴力,但可能会出现"循环"【一直不会FALL DOWN,直到超出第N个PLATFORM】。则循环一定是又跳到0。即D%M==0的第一个位置。

 

代码:

ll n,d,m,l;

int main(){

    cin>>n>>d>>m>>l;
    ll D=0;
    for(;;){
        ll t=D%m;
        if(t>l){
            print("%I64d\n",D);
            ret 0;
        }
        if(D&&D%m==0){
            print("%I64d\n",((n-1)*m+l)/d*d+d);
            ret 0;
        }
        D+=d;
    }

    return 0;
}

 

cf18B Platforms(仔细谨慎题)

标签:

原文地址:http://www.cnblogs.com/fish7/p/4329889.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!