Codeforces Round #272 (Div. 2)-A. Dreamoon and Stairs
http://codeforces.com/contest/476/problem/A
1 second
256 megabytes
standard input
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?
The single line contains two space separated integers n, m (0 < n ≤ 10000, 1 < m ≤ 10).
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.
10 2
6
3 5
-1
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的更多相关文章
- Codeforces Round #272 (Div. 2) A. Dreamoon and Stairs 水题
A. Dreamoon and Stairs 题目连接: http://www.codeforces.com/contest/476/problem/A Description Dreamoon wa ...
- Codeforces Round #272 (Div. 2) E. Dreamoon and Strings 动态规划
E. Dreamoon and Strings 题目连接: http://www.codeforces.com/contest/476/problem/E Description Dreamoon h ...
- Codeforces Round #272 (Div. 2) D. Dreamoon and Sets 构造
D. Dreamoon and Sets 题目连接: http://www.codeforces.com/contest/476/problem/D Description Dreamoon like ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- yarn 基础
创建: 2019/04/06 安装 mac brew install yarn 升级 brew upgrade yarn 确认是否成功 yarn --version 初始化项目 yarn ini ...
- E20180615-hm
fraction n. [数] 分数; 一小部分,些微; 不相连的一块,片段; [化] 分馏; infinity n. <数>无穷大; 无限的时间或空间; product n. 产品; ...
- [HNOI2010] 公交线路 bus
标签:状态压缩+矩阵快速幂. 题解: 首先看范围,p<=10,那么我们可以想到状态压缩.我们把从一个长度为10的区间进行压缩,1代表可以,那么当值一个区间的1的个数为k个,我们就认为他是合法的. ...
- 关于Dictionary的优化用法
今天突然想到了解一下Dictionary,于是在博客园上看到了一篇关于用TryGetValue的文章,原来用TryGetValue要比用ContainsKey更快,快一倍.
- Eclipse - 安装了jd-eclipse插件后依然无法反编译类文件
问题 Eclipse在安装了jd-eclipse插件后依然无法反编译类文件,这个问题是因为没有修改默认的类文件查看器. 解决方法 修改默认的类文件查看器为jd-eclipse Window -> ...
- win 7启动tensorboard的详尽步骤
TensorBoard是TensorFlow下的一个可视化的工具,能够帮助我们在训练大规模神经网络过程中出现的复杂且不好理解的运算.TensorBoard能展示你训练过程中绘制的图像.网络结构等. 1 ...
- java中代码执行顺序
静态代码块 -- >构造代码块 --> 构造方法静态代码块:只执行一次构造代码块:每次调用构造方法都执行 http://blog.csdn.net/wuhaiwei002/article/ ...
- [在读]HTML5数据推送应用开发
最近买的,讲SSE的,才看完前2章.
- Nginx upstream负载均衡配置
1.在http节点下添加 upstream test { server 127.0.0.1:16010; server 127.0.0.1:16011; } 2.把server 节点下 ...
- javaScript面向对像
1.创建对象 <script type="text/javascript"> function Flower(name,addre) { this.name=name; ...