zoukankan      html  css  js  c++  java
  • Codeforces Round #272 (Div. 2) A. Dreamoon and Stairs 水题

    A. Dreamoon and Stairs

    题目连接:

    http://www.codeforces.com/contest/476/problem/A

    Description

    Dreamoon wants to climb up a stair of n steps. He can climb 1 or 2 steps at each move. Dreamoon wants the number of moves to be a multiple of an integer m.

    What is the minimal number of moves making him climb to the top of the stairs that satisfies his condition?

    Input

    The single line contains two space separated integers n, m (0 < n ≤ 10000, 1 < m ≤ 10).

    Output

    Print a single integer — the minimal number of moves being a multiple of m. If there is no way he can climb satisfying condition print  - 1 instead.

    Sample Input

    10 2

    Sample Output

    6

    Hint

    题意

    有一个长度为n个阶梯,你要爬到顶,你可以一次爬一格,也可以一次爬两格

    问你最少爬多少次,才能使得你爬到顶,而且你爬的次数恰好是m的倍数

    题解:

    数据范围很小,直接暴力爬就好了

    代码

    #include<bits/stdc++.h>
    using namespace std;
    
    int main()
    {
        int n,m;
        scanf("%d%d",&n,&m);
        int ans = 1e9;
        for(int i=0;i<=n;i++)
        {
            if((n-i)%2)continue;
            int step=i+(n-i)/2;
            if(step%m==0)ans=min(ans,step);
        }
        if(ans==1e9)cout<<"-1"<<endl;
        else cout<<ans<<endl;
    }
  • 相关阅读:
    wait 和 notify 方法
    synchronized关键字
    多线程之thread、runnable的区别
    CodeForces 213 E
    hdu 3038 并查集
    zoj 3349 dp + 线段树优化
    hdu 4419 线段树 扫描线 离散化 矩形面积
    hdu 4262(线段树)
    hfut 1287
    hdu 4747 (线段树)
  • 原文地址:https://www.cnblogs.com/qscqesze/p/5793603.html
Copyright © 2011-2022 走看看