本文主要是介绍Codeforces Round #272 (Div. 2) A,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
A. Dreamoon and Stairs
题意:n级台阶,每次上1或2级,上的总次数需要为m的倍数,问最少上几次。
思路:从n/2(n为奇数从n/2+1)开始枚举,发现能被m整除即是答案。
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstdlib>
#include <string>
#include <memory.h>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <ctype.h>
#include <sstream>
#define INF 1000000000
#define ll long long
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define MAXN 100010 using namespace std; int main(){int n,m;while(cin>>n>>m){int tmp=n/2;if(n&1)tmp++;int ans=-1;for(int i=tmp;i<=n;i++){if(i%m==0){ans=i;break;}}cout<<ans<<endl;}return 0;
}
这篇关于Codeforces Round #272 (Div. 2) A的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!