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 ...
随机推荐
- [WIP]webpack入门
创建: 2019/04/09 安装 npm install --save-dev webpack # 最新版 npm install --save-dev webpack@<version&g ...
- node-sass安装失败
1. 直接安装报错(版本根据自己需求来) npm i node-sass@ -D 报错不能下载 win32-x64-64_binding.node Downloading binary from ht ...
- uoj#79. 一般图最大匹配(带花树)
传送门 带花树 不加证明的说一下过程好了:每次从一个未匹配点\(S\)出发bfs,设\(S\)为\(1\)类点,如果当前点\(v\)在本次bfs中未经过,分为以下两种情况 1.\(v\)是未匹配点,那 ...
- 后Selenium时代,网页自动化测试用Cypress
本文技术难度★★★,初学自动化测试的朋友慎点!否则会引起焦虑等不适症状,严重者会怀疑自己技术人生! 来自Cypress官网首页! Web开发飞速换代! table控制页面OUT了! 原生态手写网页OU ...
- mysql之SQL入门与提升(四)——终结篇,函数
一.SQL Aggregate (聚合)函数 SQL Aggregate 函数计算从列中取得的值,返回一个单一的值. AVG() - 返回平均值 COUNT() - 返回行数 FIRST() - 返回 ...
- 第二篇 HTML5打包发布IOS APP之苹果开发者账号申请流程
打包技术转移到了公众号
- 分布式通信-tcp/ip socket
Socket通讯的过程 Server端Listen(监听)某个端口是否有连接请求,Client端向Server 端发出Connect(连接)请求,Server端向Client端发回Accept(接受) ...
- js_jquery
引用 jQuery 是一个 JavaScript 库,不需要安装,直接引用就行 <!-- jQuery --> <script src="/static/vendors/j ...
- CentOS7 adb
https://blog.csdn.net/u012700515/article/details/79021320
- python 基础(十五) socket编程
SOCKET TCP协议: 有请求 有响应 称之为 tcp协议 是面向连接的协议 就是在收发数据之前 必须先要建立一个可靠的链接 三次握手 如:网站 UDP协议: 是一个非链接的协议 传输之前不需要键 ...