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. C++虚继承作用

    C++虚继承可以防止多重继承产生的二义性问题. 虚继承,就是在被继承的类前面加上virtual关键字,这时被继承的类称为虚基类,如下面代码中的base类.虚继承在多重继承的时可以防止二义性. clas ...

  2. DOM中元素节点、属性节点、文本节点的理解13.3

    节点信息 每个节点都拥有包含着关于节点某些信息的属性.这些属性是:nodeName(节点名称) nodeValue(节点值) nodeType(节点类型) nodeType nodeType 属性可返 ...

  3. POJ3463【次短路】

    转自:http://www.cnblogs.com/jackge/archive/2013/04/29/3051273.html 算法:最短路和次短路.Dijkstra算法.采用邻接表建图. 总结:不 ...

  4. studio 配置 opencv3.1

    环境 win10 android studio2.0 OpenCV-3.1.0-android-sdk android-ndk-r10e-windows-x86_64 jdk-8u102-window ...

  5. 3DMAX 烘培技术

    烘培是指,把光照信息渲染成贴图,而后把这个烘培后的贴图再贴回到场景中去的技术.烘培技术把光照计算的结果提前写入到了贴图中,因此在实时渲染中不需要进行耗时的光照计算,大大提高了实时渲染的效率. 烘培和渲 ...

  6. 計蒜課/排澇(Edmond-Karp)

    題目鏈接: https://nanti.jisuanke.com/t/36 題意:中文題目誒~ 思路: 最大流模板題.... 關於最大流算法blog: http://www.cnblogs.com/z ...

  7. spring boot 配置https 报这个错误:java.lang.IllegalArgumentException: Private key must be accompanied by certificate chain

    找了接近半天的时间,原来是那么小的问题 server.ssl.key-store=test.jksserver.ssl.key-store-password=123456server.ssl.key- ...

  8. Zynq7000开发系列-2(VMware与Ubuntu安装使用)

    一.前言 在嵌入式开发中,是无法避免使用Linux系统的,因为在开发之前必须先搭建起交叉编译环境,而后关于Bootloader.Linux Kernel的裁剪移植,File system的制作,底层驱 ...

  9. DDX_Text详细用法

    void AFXAPI DDX_Text( CDataExchange* pDX, int nIDC, BYTE& value ); void AFXAPI DDX_Text( CDataEx ...

  10. LVDT

    什么是 LVDT? LVDT 是线性可变差动变压器的缩写. 它是一种常见类型的机电传感器,可将其以机械方式耦合的物体的直线运动转换为对应的电气信号.LVDT 线性位移传感器随时可用,可以测量各种移动, ...