Floor Number - 每天一把CF - 20201018

每天一把CF : 2020-10-17

800分牛逼

题目

原题链接:https://codeforces.com/problemset/problem/1426/A

在这里插入图片描述

思路

题目大意:现规定数1-n:1,2属于1楼,之后每x个数属于一楼,给定n和x,确定n所在的楼数.

思路:n/2+1+(n%2?1:0) 不想多解释

代码实现

#include <iostream>
#include <cstring>
#include <algorithm>
#include <map>

using namespace std;

const int MAX = 1e5 + 5;

int t,n,x,ans;

int main() {
    
    
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	cin >> t;
	while (t--) {
    
    
		cin >> n >> x;
		if (n <= 2) {
    
    
			ans = 1;
		}
		else {
    
    
			ans = 1 + (n - 2) / x + ((n - 2) % x ? 1 : 0);
		}
		cout << ans << endl;
	}

	return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_45761327/article/details/109150760
今日推荐