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;
}
Codeforces Round #272 (Div. 2) A. Dreamoon and Stairs 水题的更多相关文章
- Codeforces Round #272 (Div. 2)-A. Dreamoon and Stairs
http://codeforces.com/contest/476/problem/A A. Dreamoon and Stairs time limit per test 1 second memo ...
- Codeforces Round #394 (Div. 2) A. Dasha and Stairs 水题
A. Dasha and Stairs 题目连接: http://codeforces.com/contest/761/problem/A Description On her way to prog ...
- Codeforces Round #297 (Div. 2)A. Vitaliy and Pie 水题
Codeforces Round #297 (Div. 2)A. Vitaliy and Pie Time Limit: 2 Sec Memory Limit: 256 MBSubmit: xxx ...
- Codeforces Round #290 (Div. 2) A. Fox And Snake 水题
A. Fox And Snake 题目连接: http://codeforces.com/contest/510/problem/A Description Fox Ciel starts to le ...
- Codeforces Round #322 (Div. 2) A. Vasya the Hipster 水题
A. Vasya the Hipster Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/581/p ...
- Codeforces Round #373 (Div. 2) B. Anatoly and Cockroaches 水题
B. Anatoly and Cockroaches 题目连接: http://codeforces.com/contest/719/problem/B Description Anatoly liv ...
- Codeforces Round #368 (Div. 2) A. Brain's Photos 水题
A. Brain's Photos 题目连接: http://www.codeforces.com/contest/707/problem/A Description Small, but very ...
- Codeforces Round #359 (Div. 2) A. Free Ice Cream 水题
A. Free Ice Cream 题目连接: http://www.codeforces.com/contest/686/problem/A Description After their adve ...
- Codeforces Round #355 (Div. 2) A. Vanya and Fence 水题
A. Vanya and Fence 题目连接: http://www.codeforces.com/contest/677/problem/A Description Vanya and his f ...
随机推荐
- SPOJ 8222 NSUBSTR - Substrings
http://www.spoj.com/problems/NSUBSTR/ 题意: F(x)定义为字符串S中所有长度为x的子串重复出现的最大次数 输出F[1]~F[len(S)] 用字符串S构建后缀自 ...
- UVA 12307 Smallest Enclosing Rectangle
https://vjudge.net/problem/UVA-12307 求覆盖所有点的最小矩形面积.周长 相当于求凸包的最小面积外接矩形.最小周长外接矩形 结论: 这个矩形一定有一条边和凸包上一条边 ...
- android tools相关
1.showin 在include 的根节点设置,可一预览效果
- html5 canvas贝塞尔曲线篇(上)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- Windows bat 学习(高级)
有一种叫做 Command Processor Extensions 的东西,即命令处理器扩展.他会使命令更加高级,功能更多. 在 cmd 里可以使用 ECHO %CMDEXTVERSION% 查看当 ...
- HTTP::UserAgent注意问题
例用 HTTP::Request 设置头信息时, 比如 add-content , 第二次再执行 add-content 时, content 内容会追加, 并不会重新添加. 当下次再 add-con ...
- win10 安装IIS说明操作
1.点左下角的Windows,所有应用,找到Windows系统,打开控制面板. 2.进入控制面板之后点击程序,可能你的控制面板和图片里的不太一样,不过没关系,找到程序两个字点进去就行. 3.接下来,在 ...
- PGP工作原理及其安全体制
现代信息社会里,当电子邮件广受欢迎的同时,其安全性问题也很突出.实际上,电子邮件的传递过程是邮件在网络上反复复制的过程,其网络传输路径不确定,很容易遭到不明身份者的窃取.篡改.冒用甚至恶意破坏,给收发 ...
- Long-Polling, Websockets, SSE(Server-Sent Event) 之间有什么区别?
链接:http://www.mamicode.com/info-detail-1327667.html https://www.jianshu.com/p/d3f66b1eb748?from=time ...
- java 异常的限制
一. 1.) 在覆盖方法的时候,只能抛出在基类方法的异常说明里列出的那些异常 2.) 在基类构造器声明的异常,在子类必须抛出,子类的构造器可以抛出任何异常,但是必须抛出基类构造器的异常 3.) 在基类 ...