0
点赞
收藏
分享

微信扫一扫

A. Floor Number(水题) Codeforces Round #674 (Div. 3)

九点韶留学 2022-06-24 阅读 105

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

A. Floor Number(水题)   Codeforces Round #674 (Div. 3)_ios
测试样例

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.

题意: 给你公寓编号,判断在第几楼层。

解题思路: 题目描述的很详细了,就是第一层公寓数为A. Floor Number(水题)   Codeforces Round #674 (Div. 3)_i++_02,其余为A. Floor Number(水题)   Codeforces Round #674 (Div. 3)_ios_03。那么直接判断对第一层特判就行,其余层利用除法即可解决。

AC代码

/*

*
*/
#include<bits/stdc++.h> //POJ不支持

#define rep(i,a,n) for (int i=a;i<=n;i++)//i为循环变量,a为初始值,n为界限值,递增
#define per(i,a,n) for (int i=a;i>=n;i--)//i为循环变量, a为初始值,n为界限值,递减。
#define pb push_back
#define IOS ios::sync_with_stdio(false);cin.tie(0); cout.tie(0)
#define fi first
#define se second
#define mp make_pair

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


举报

相关推荐

0 条评论