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 ...
随机推荐
- 黑科技抢先尝 - Windows全新终端初体验(附无需编译就能安装的Preview版本及代码Build全过程)
目录 将Window 10 升级到1903版本 安装好git, 从github上clone代码 安装 VS 2019 和 .NET core 3.0 SDK 重定解决方案目标 设置好编译平台和启动的项 ...
- E20181029-hm
cardinality 基数 entity n. 实体; 实际存在物; 本质; distribute vt. 分配,散布; 散发,分发; 把…分类; [电] 配电; replica n. 复制品; ...
- java模拟进程调度之模拟抢占试多级轮转调度(附带可视化解决方案)
1.简介一下多级轮转调度 多级轮转调度是一种提高调度效率的解决方案,简单讲就是讲要执行的程分成几个优先级的列队即例如三个,第一个列队分10个时间片,第二个列队分配1000个时间片,第三个列队表示100 ...
- 远程kafka通信实例,各种bug解决----虚拟机+本地电脑
为了实现远程kafka通信,我可谓是呕心沥血.期间各种bug各种调,太煎熬了 (T.T) 介绍: 我用一台虚拟机作为远程消息的发送方,用本地电脑主机作为消息的接收方 虚拟机:安装java,kafka, ...
- C 语言实例 - 将字符串写入文件
C 语言实例 - 将字符串写入文件 C 语言实例 C 语言实例 将字符串写入文件. 实例 #include <stdio.h> #include <stdlib.h> /* e ...
- Codeforces 1136E(转化+线段树维护)
题目传送 虽然线段树比较显然但是发现a数组并不好维护.考虑将a转化为好维护的数组b. 方法 这里我将k[1]设为0,对应着\[a[1] + k[1] <= a[2]\]不难得出\[a[i] + ...
- HDU4405(期望dp)
标准期望套路,很水.读题看好是到n就可以停止了. ; int n, m; db dp[maxn]; map<int, int> mp; int main() { while (~scanf ...
- python_19(Django外键)
第1章 Django ORM相关操作 1.1 在一个py文件中使用django项目 1.2 返回QuerySet对象的方法有 1.2.1 特殊的QuerySet 1.3 返回具体对象的 1.4 返回布 ...
- Unity Shader入门精要学习笔记 - 第2章 渲染流水线
来源作者:candycat http://blog.csdn.net/candycat1992/article/ 2.1 综述 渲染流水线的最终目的在于生成或者说是渲染一张二维纹理,即我们在电脑屏 ...
- php中socket的使用(重点参考)
一.开启socket phpinfo();查看是否开启了socket扩展,否则在php.ini中开启. 二.服务器端代码的写法 <?php error_reporting(E_ALL); set ...