0分求助
查看原帖
0分求助
994681
arcticfox_LQX楼主2024/5/25 15:46

课程中过,但样例全错

#include <bits/stdc++.h>
using namespace std;
int n;
int calc(int x) {
    int total = x;
    while(x>=3) { 
        total++;
        x-=3;
    }
    return total;
}
int main() {
    int l, r, mid, ans;
    cin >> n;
    l = 1; r = n;
    ans = n;
    while(l <= r) {
        mid = (l + r) / 2;
        if(calc(mid) >= n) { 
            ans=min(ans,mid); 
            r=mid-1; 
        } else
            l=mid+1; 
    } 
    cout << ans ;
    return 0;
}
2024/5/25 15:46
加载中...