Floor Number-One CF per day-20201018

One CF every day: 2020-10-17

800 points awesome

topic

Original title link: https://codeforces.com/problemset/problem/1426/A

Insert picture description here

Ideas

The main idea of ​​the topic: Now it is stipulated that the number 1-n:1, 2 belongs to the first floor, and then every x number belongs to the first floor, given n and x, determine the number of buildings where n is located.

Idea: n/2+1+(n%2?1:0) I don’t want to explain more

Code

#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;
}

Guess you like

Origin blog.csdn.net/weixin_45761327/article/details/109150760