当前位置: 代码迷 >> 综合 >> Codeforces Round #674 (Div. 3) A. Floor Number
  详细解决方案

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

热度:63   发布时间:2024-02-23 22:52:44.0

在这里插入图片描述

题意:T组输入,每组输入一个n,x,n为需要到的门牌号,x为第二层以上每层有多少户,无论什么情况,第一层只有2户,求n号在第几层
题解:读懂即可ac
code:

#include<bits/stdc++.h>#pragma GCC optimize(2)
#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为界限值,递减。using namespace std;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0)
#define ll long long
#define ull unsigned long long
#define ld long double
const int INF = 0x3f3f3f3f;
const ll LINF = 1ll<<60;
const int mod=1e9+7;ll read()//快读
{
    ll w = 1, s = 0;char ch = getchar();while (ch < '0' || ch>'9') {
     if (ch == '-') w = -1; ch = getchar(); }while (ch >= '0' && ch <= '9') {
     s = s * 10 + ch - '0';    ch = getchar(); }return s * w;
}
void solve(){
    ll  n,x;cin>>n>>x;if(n>2){
    if(n>x){
    cout<<((n-2)+(x-1))/x+1<<endl;}else cout<<2<<endl;}else cout<<1<<endl;
}int main(){
    int _;cin>>_;while(_--) solve();return 0;
}
  相关解决方案