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