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

A. Dreamoon and Stairs
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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 nm (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  - 1instead.

Sample test(s)
input
10 2
output
6
input
3 5
output
-1
Note

For the first sample, Dreamoon could climb in 6 moves with following sequence of steps: {2, 2, 2, 2, 1, 1}.

For the second sample, there are only three valid sequence of steps {2, 1}, {1, 2}, {1, 1, 1} with 2, 2, and 3 steps respectively. All these numbers are not multiples of 5.

解题思路:一个N阶的楼梯,每次能走1,或者2阶,求最小的爬完楼梯的次数,且要满足次数是m的倍数

贪心,枚举最少走2阶且满足条件的次数

 1 #include <stdio.h>
 2 
 3 int main(){
 4     int x, y, n, m, min;
 5     while(scanf("%d %d", &n, &m) != EOF){
 6         min = ;
 7         for(y = ; y <= n / ; y++){
 8             x = n -  * y;
 9             if((x + y) % m == ){
                 if((x + y) < min){
                     min = x + y;
                 }
             }
         }
         if(min != ){
             printf("%d\n", min);
         }
         else{
             printf("-1\n");
         }
     }
     return ;

23 }

Codeforces Round #272 (Div. 2)-A. Dreamoon and Stairs的更多相关文章

  1. Codeforces Round #272 (Div. 2) A. Dreamoon and Stairs 水题

    A. Dreamoon and Stairs 题目连接: http://www.codeforces.com/contest/476/problem/A Description Dreamoon wa ...

  2. Codeforces Round #272 (Div. 2) E. Dreamoon and Strings 动态规划

    E. Dreamoon and Strings 题目连接: http://www.codeforces.com/contest/476/problem/E Description Dreamoon h ...

  3. Codeforces Round #272 (Div. 2) D. Dreamoon and Sets 构造

    D. Dreamoon and Sets 题目连接: http://www.codeforces.com/contest/476/problem/D Description Dreamoon like ...

  4. Codeforces Round #272 (Div. 2) B. Dreamoon and WiFi dp

    B. Dreamoon and WiFi 题目连接: http://www.codeforces.com/contest/476/problem/B Description Dreamoon is s ...

  5. Codeforces Round #272 (Div. 2) E. Dreamoon and Strings dp

    题目链接: http://www.codeforces.com/contest/476/problem/E E. Dreamoon and Strings time limit per test 1 ...

  6. Codeforces Round #272 (Div. 1) A. Dreamoon and Sums(数论)

    题目链接 Dreamoon loves summing up something for no reason. One day he obtains two integers a and b occa ...

  7. Codeforces Round #272 (Div. 2)-C. Dreamoon and Sums

    http://codeforces.com/contest/476/problem/C C. Dreamoon and Sums time limit per test 1.5 seconds mem ...

  8. Codeforces Round #272 (Div. 2)-B. Dreamoon and WiFi

    http://codeforces.com/contest/476/problem/B B. Dreamoon and WiFi time limit per test 1 second memory ...

  9. Codeforces Round #272 (Div. 2)C. Dreamoon and Sums 数学推公式

    C. Dreamoon and Sums   Dreamoon loves summing up something for no reason. One day he obtains two int ...

随机推荐

  1. 求N!的长度【数学】

    转自:http://blog.csdn.net/fengdian29147001/article/details/11992755 给一个数X,len=log10(X)+1就是X这个数的长度 ①:当N ...

  2. bzoj 4464: [Jsoi2013]旅行时的困惑【贪心】

    据说正解是有上下界最小流,但是这种1e5的玩意问什么要跑网络流啊-- 贪心即可,注意一点是可以有多条路径经过一条边-- 以1为根,设d[u][0/1]为u到父亲的边是向下/向上,g记录这个点儿子中不能 ...

  3. TensorFlow数据集(二)——数据集的高层操作

    参考书 <TensorFlow:实战Google深度学习框架>(第2版) 一个使用数据集进行训练和测试的完整例子. #!/usr/bin/env python # -*- coding: ...

  4. 线程安全 原子性 可见性 顺序性 volatile

  5. [arc063]F.すぬけ君の塗り絵2

    因为这题考虑可以观察一个性质,答案的下界为 \(2×(max(w,h)+1)\), 因为你至少可以空出一行或一列,因此这个矩形一定会经过 \(x=\frac{w}{2}\) 或 \(y=\frac{h ...

  6. GYM 101889I(mst+lca)

    最小生成树上倍增询问裸的. const int maxn = 2e5 + 5; int n, m, q; //图 struct Edge { int u, v; ll cost; bool opera ...

  7. Codeforces Round #497 (Div. 2)B. Turn the Rectangles

    Bryce1010模板 http://codeforces.com/contest/1008/problems #include <bits/stdc++.h> using namespa ...

  8. bzoj 4318 || 洛谷P1654 OSU!

    https://www.lydsy.com/JudgeOnline/problem.php?id=4318 https://www.luogu.org/problemnew/show/P1654 看来 ...

  9. python学习之环境搭建 输入输出

    一 环境搭建: 在安装好python2.7之后就可以利用其命令行和交互式模式进行基本的输入和输出测试了,但这样编码无法保存,所以就需要用到好用的编辑器和环境搭建了,这里用uestdio. 1.1打开u ...

  10. python_19(Django外键)

    第1章 Django ORM相关操作 1.1 在一个py文件中使用django项目 1.2 返回QuerySet对象的方法有 1.2.1 特殊的QuerySet 1.3 返回具体对象的 1.4 返回布 ...