Floor Number - 每天一把CF - 20201018
发表时间:2020-10-18
发布人:葵宇科技
浏览次数:37
每天一把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;
}