zoukankan      html  css  js  c++  java
  • cf18B Platforms(仔细谨慎题)

    题意:

    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
    ",D);
                ret 0;
            }
            if(D&&D%m==0){
                print("%I64d
    ",((n-1)*m+l)/d*d+d);
                ret 0;
            }
            D+=d;
        }
    
        return 0;
    }
  • 相关阅读:
    MacOS如何正确配置Idea自带Maven插件的环境变量?(亲测)
    通过Canvas实现画板
    插入排序
    选择排序
    冒泡排序法
    进制
    JDBC(宠物管理系统)
    银行ATM存取款机系统MySQL数据库
    高级查询(二)
    高级查询
  • 原文地址:https://www.cnblogs.com/fish7/p/4329889.html
Copyright © 2011-2022 走看看