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;
}

最新文章

  1. suggest插件实现下拉选择筛选
  2. 创建一个Windows的NTP Server
  3. @JoinColumn
  4. SQLserver分页查询实例
  5. YTU 2616: A代码完善--简易二元运算
  6. 【风马一族_Java】在某个范围内,找出具有水仙花特征的数字
  7. Android 实现闹钟功能
  8. webpack资料
  9. AmpLab Tachyon and Shark update
  10. 记一次vscode升级后,格式化Vue出现的问题
  11. 洛谷P1854 花店橱窗布置 分析+题解代码
  12. Docker配置加速器
  13. 动态SQL中不同变量的写法总结
  14. SCSS &amp; SASS Color 颜色函数用法
  15. vuecli3.0安装搭建项目
  16. servlet篇 之 生命周期
  17. 读取CSV到DataTable
  18. springboot + websocket + spring-messaging实现服务器向浏览器广播式
  19. vue 开发系列(一) vue 开发环境搭建
  20. 在家赚钱,威客网站的使用方法 CSDN项目频道、SXSOFT、任务中国、猪八戒四个网站的线上交易 三种交易模式(1)悬赏模式(2)招标模式(3)直接交易模式

热门文章

  1. javascript模块模式
  2. ML—机器学习常用包(持续更新….)
  3. c++ 函数指针简单实例
  4. C++单链表反转
  5. orm 缺点
  6. tar.gz tar.bz2的解压命令
  7. 2013 ACM/ICPC 杭州网络赛C题
  8. LeetCode(15): 每k个一组翻转链表
  9. 解决Python3 pip list 红色DEPRECATION
  10. 记一些使用PyQt的问题