CF713div3 F

Problem - F - Codeforces

题意:

小明想买一个价值为c的东西,他开始打工,他一开始在第i个职务,每天可以挣a[i],他也可以用一天的时间并且花费b[i]升到i+1职务,第i+1职务每天可以挣a[i+1]

一共有n个职务,问他最少要多少天才能攒够钱c

2<=n<=2e5

思路:

注意这道题的复杂度

如果他晋升,那么晋升的那一级的状态是确定

如果不晋升,那么考虑枚举在哪一级截止不晋升,复杂度O(n)级别

综上,这道题的复杂度是O(n)级别

因此直接枚举即可!

直接去枚举在第i级别停止一共需要多少天能攒够c

#include <bits/stdc++.h>
#define int long long
const int mxn=2e5+10;
const int mxe=2e5+10;
using namespace std;




int n,c;
int a[mxn],b[mxn];
void solve(){
    memset(a,0,sizeof(a));
    memset(b,0,sizeof(b));
    cin>>n>>c;
    for(int i=1;i<=n;i++) cin>>a[i];
    for(int i=1;i<=n-1;i++) cin>>b[i];
    int tot=0,pretot=0,preday=0,day=0;
    int ans=1e18;
    for(int i=1;i<=n;i++){
        tot=preday+ceil((1.0*(c-pretot))/(1.0*a[i]));//在第i天截止攒够钱的天数
        day=ceil(1.0*(b[i]-pretot)/(1.0*(a[i])));//晋升所需天数,这是确定的,是O(1)级别
        preday+=(day+1);
        pretot+=day*a[i]-b[i];
        ans=min(ans,tot);
    }
    cout<<ans<<'\n';
}
signed main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int __=1;cin>>__;
    while(__--)solve();return 0;
}
<div id="wea_rich_text_default_font" style="font-family:微软雅黑;font-size:12;"><p><img alt="" src="/weaver/weaver.file.FileDownload?fileid=aaa9aee4717d33272bd7ea028fa03118b693919f23b18febf9f6cee1158e8f4cf027542c71c8cf98d63770ccdf3bd1750e6b92e28c43dccd4" /></p><div class="ckeditor-html5-video" data-widget="html5video" style="text-align:left"><video controls="controls" src="/weaver/weaver.file.FileDownload?fileid=aad6f413f83191673980c5ee24b412880d6b9e8703caca411faec3276fe8133f5fa7e34630ca89ace63770ccdf3bd175071362141037cfb4e&download=1" style="max-width:100%"> </video></div><table border="1" cellpadding="1" style="width:500px;"> <tbody> <tr> <td style="padding: 1px;">1</td> <td style="padding: 1px;">1</td> </tr> <tr> <td style="padding: 1px;">2</td> <td style="padding: 1px;">2</td> </tr> <tr> <td style="padding: 1px;">3</td> <td style="padding: 1px;">3<a href="http://localhost:8080/wui/index.html#/main/portal/portal-1-1?menuIds=0,1&menuPathIds=0,1&_key=zq8830" target="_blank">http://localhost:8080/wui/index.html#/main/portal/portal-1-1?menuIds=0,1&menuPathIds=0,1&_key=zq8830</a></td> </tr> </tbody></table><p>测试<a href="http://localhost:8080/wui/index.html#/main/portal/portal-1-1?menuIds=0,1&menuPathIds=0,1&_key=zq8830" target="_blank">http://localhost:8080/wui/index.html#/main/portal/portal-1-1?menuIds=0,1&menuPathIds=0,1&_key=zq8830</a></p><p> </p><p>修改一下吧 qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq<img alt="" src="/weaver/weaver.file.FileDownload?fileid=a7617945ec5f52ec80aaa43ee8504de0a1b14d5eca4a98834494c85349762c626dec7ba8d0da277106ee600d27743f4e44f710fbddd167603" /></p></div>
06-01

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值