原题链接: https://codeforces.com/contest/1426/problem/A
测试样例
input
4
7 3
1 5
22 5
987 13
output
3
1
5
77
Note
Consider the first test case of the example: the first floor contains apartments with numbers 1 and 2, the second one contains apartments with numbers 3, 4 and 5, the third one contains apartments with numbers 6, 7 and 8. Therefore, Petya lives on the third floor.
In the second test case of the example, Petya lives in the apartment 1 which is on the first floor.
题意: 给你公寓编号,判断在第几楼层。
解题思路: 题目描述的很详细了,就是第一层公寓数为,其余为。那么直接判断对第一层特判就行,其余层利用除法即可解决。
AC代码
/*
*
*/
//POJ不支持
//i为循环变量,a为初始值,n为界限值,递增
//i为循环变量, a为初始值,n为界限值,递减。
using namespace std;
const int inf = 0x3f3f3f3f;//无穷大
const int maxn = 1e5;//最大值。
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
//*******************************分割线,以上为自定义代码模板***************************************//
int t;
int n,x;
int main(){
//freopen("in.txt", "r", stdin);//提交的时候要注释掉
IOS;
while(cin>>t){
while(t--){
cin>>n>>x;
if(n<=2){
cout<<1<<endl;
}
else{
n-=2;
cout<<(n-1)/x+2<<endl;
}
}
}
return 0;
}