P1843 奶牛晒衣服

P1843 奶牛晒衣服

题目分析:

  • 数据范围:

  • 为了避免踩坑,用long long型
  • 求解弄干所有衣服的时间
  • 二分答案区间[l,r] (l = 1,r = inf)

注意:

  • 踩坑了,int改半天,w[i] - a * x里面乘以x可能爆int,用long long啊

代码如下:

#include<cstdio>
#include<cmath>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>

using namespace std;

#define inf 0x3f3f3f3f
#define eps 1e-6
#define db double
#define ll long long
#define  mm(a,x) memset(a,x,sizeof a)
#define pii pair<int,int>
#define pb push_back
#define el endl
#define debug(x) cerr<<#x<<" = "<<x<<endl
#define fgx cerr<<"-------------------------"<<endl
#define shutio ios::sync_with_stdio(false),cin.tie(0)
#define  mk make_pair
#define lowbit(x) (x) & (-x)
#define fi first
#define se second

const int N = 1e6 + 10;

ll n,a,b;
ll w[N];
ll l,r;

bool check(ll x){
    ll tot = 0;
    for(int i = 0; i < n; i ++ ){
        ll t = w[i] - a * x;
        if(t > 0){
            if(t % b == 0) tot += t/b;
            else tot += t/b + 1; 
        }
    }
    return tot<=x;    
}

int main() {
    shutio;
    cin >> n >> a >> b;
    ll l = 1,r = inf;    
    for(int i = 0; i < n; i ++ ){
        cin >> w[i];
    }
    while(l < r){
        ll mid = (l + r) >> 1;
        if(check(mid)) r = mid;
        else l = mid + 1;
    }
    cout<<l;                
    return 0;
}
全部评论

相关推荐

求问!考研下岸,打算参加春招,我这个bg能进啥厂,或者需要搞点深度项目再投吗
Java抽象带篮子_...:直接海投,可以看看我的考研失利速成冲春招贴,里面详细写了简历怎么写,学哪些项目可以速成
点赞 评论 收藏
分享
03-06 20:09
贵州大学 Java
King987:你这个学历找个中大厂刷实习经历都是可以的,但是项目要有亮点才行,这个什么外卖就不要做了,去找找最新的项目,至少涉及高并发或者是新型的AI技术mcp rag啥的 ,我在出简历点评,但是你这个没什么好点评的,内容太少,而且含金量太低。自己改一改吧,或者看一下我的项目地址中,那里有大厂最近做过的实习项目
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务