• 题意:有一个HP为\(h\)的大怪兽,你需要轮流进行\(i\)次操作.每次可以使\(h+=d_i\)(\(d_i\)有正有负),当第\(n\)次操作完成后,再从第一次开始,问能否使得怪兽的HP变为\(0\)或更低,如果可以,输出操作次数,否则输出\(-1\).

  • 题解:我们首先求\(d\)的前缀和,如果在求的过程中就能使怪兽死掉的话,直接输出即可.然后再去判断\(pre[n]\)是否小于\(0\),如果不小于,那么我们每一个循环得到的都是正的贡献,永远也打不死怪兽!再来看.我们最后的操作次数一定是刚好跑了几个循环,或者跑了几个循环后再从起始位置选了几个,所以我们可以枚举前缀和,每次减去当前前缀和,然后再去求循环次数(除以\(pre[n]\)上取整),更新答案的最小值就好了.

  • 代码:

    ll h;
    int n;
    ll d[N];
    ll pre[N];
    ll ans=1e18; int main() {
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    cin>>h;
    cin>>n; rep(i,1,n){
    cin>>d[i];
    } rep(i,1,n){
    pre[i]=pre[i-1]+d[i];
    if(pre[i]<=-h){
    cout<<i<<'\n';
    return 0;
    }
    }
    if(pre[n]>=0) {cout<<-1<<'\n';return 0;}
    pre[n]=-pre[n];
    rep(i,0,n){
    ll cur=h;
    cur+=pre[i];
    ll cnt=(cur-1)/pre[n]+1;
    ans=min(ans,cnt*n+i);
    } cout<<ans<<'\n'; return 0;
    }

Codeforces Round #547 (Div. 3) E. Superhero Battle (数学)的更多相关文章

  1. Codeforces Round #547 (Div. 3) E. Superhero Battle

    E. Superhero Battle A superhero fights with a monster. The battle consists of rounds, each of which ...

  2. Codeforces Round #547 (Div. 3) 题解

    Codeforces Round #547 (Div. 3) 题目链接:https://codeforces.com/contest/1141 A,B咕咕了... C. Polycarp Restor ...

  3. E. Superhero Battle Codeforces Round #547 (Div. 3) 思维题

    E. Superhero Battle time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  4. Codeforces Round #Pi (Div. 2) D. One-Dimensional Battle Ships set乱搞

    D. One-Dimensional Battle ShipsTime Limit: 2 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/con ...

  5. Codeforces Round #Pi (Div. 2) D. One-Dimensional Battle Ships set区间分解

    D. One-Dimensional Battle ShipsTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/co ...

  6. Codeforces Round #547 (Div. 3) G 贪心

    https://codeforces.com/contest/1141/problem/G 题意 在一棵有n个点的树上给边染色,连在同一个点上的边颜色不能相同,除非舍弃掉这个点,问最少需要多少种颜色来 ...

  7. Codeforces Round #547 (Div. 3) F 贪心 + 离散化

    https://codeforces.com/contest/1141/problem/F2 题意 一个大小为n的数组a[],问最多有多少个不相交的区间和相等 题解 离散化用值来做,贪心选择较前的区间 ...

  8. Codeforces Round #547 (Div. 3) D

    http://codeforces.com/contest/1141/problem/D 题目大意: 鞋子匹配,用一个小写字母表示一种颜色.L[i]表示左脚的颜色,R[i]表示右脚的颜色,只有当L[i ...

  9. Codeforces Round #380 (Div. 2)/729D Sea Battle 思维题

    Galya is playing one-dimensional Sea Battle on a 1 × n grid. In this game a ships are placed on the ...

随机推荐

  1. Linux find 命令的初步实现(C++)

    Implement a myfind command following the find command in UNIX operating system. The myfind command s ...

  2. 二进制格式 PLY 模型文件的读取与渲染

    PLY 文件头部信息: ply format binary_little_endian 1.0 comment VCGLIB generated element vertex 13469 proper ...

  3. EXPORT和IMPORT使用示例

    1 report ztestprog. 2 data:begin of itab1 occurs 0, 3 ff(10), 4 end of itab1. 5 data:itab2 like itab ...

  4. 1V升3V芯片,1V升3.3V芯片,大电流的,低功耗

    一般来说,1V的电压实在很低了,即使是干电池的话,再1V时,也是基本属于没电状态了.还有一种是干电池输出电流大时,也会把干电池的电压从1.5V拉低到1V左右. 更多的是客户对于1V时要能升到3V或者3 ...

  5. 并发条件队列之Condition 精讲

    1. 条件队列的意义 Condition将Object监控器方法( wait , notify和notifyAll )分解为不同的对象,从而通过与任意Lock实现结合使用,从而使每个对象具有多个等待集 ...

  6. Vue之优化封装请求方法

    Vue之优化封装请求方法 对于代码中的请求操作 1.接口请求可能需要重用 2.实际工作中,接口非常容易变动, 改起来很麻烦! 我们建议的做法是把所有的请求都封装成函数然后统一的>###组织到模块 ...

  7. centos下解压rar文件,Linux解压tar.gz和tar.bz2的命令

    1.下载:根据主机系统下载合适的版本,当前64为centos系统演示下载: wget http://www.rarlab.com/rar/rarlinux-x64-5.3.0.tar.gz 2.解压安 ...

  8. 找不到:DarchetypeCatalog=local

    设置IDEA Maven->Runner 界面的VM Options参数值为-DarchetypeCatalog=local 刷新项目Maven配置,在项目右边界面,重新引入Maven

  9. Trove自动钓鱼脚本(国际服

    #WinActivateForce ; Script config. Do NOT change value here, might working inproperly! global Versio ...

  10. QR Code Error Correction

    QR Code Error Correction - QRStuff.com https://blog.qrstuff.com/2011/12/14/qr-code-error-correction ...