Codeforces1141E(E题)Superhero Battle
Each round has the same scenario. It is described by a sequence of nn numbers: d1,d2,…,dnd1,d2,…,dn (−106≤di≤106−106≤di≤106). The ii-th element means that monster's hp (hit points) changes by the value didi during the ii-th minute of each round. Formally, if before the ii-th minute of a round the monster's hp is hh, then after the ii-th minute it changes to h:=h+dih:=h+di.
The monster's initial hp is HH. It means that before the battle the monster has HH hit points. Print the first minute after which the monster dies. The monster dies if its hp is less than or equal to 00. Print -1 if the battle continues infinitely.
The first line contains two integers HH and nn (1≤H≤10121≤H≤1012, 1≤n≤2⋅1051≤n≤2⋅105). The second line contains the sequence of integers d1,d2,…,dnd1,d2,…,dn (−106≤di≤106−106≤di≤106), where didi is the value to change monster's hp in the ii-th minute of a round.
Print -1 if the superhero can't kill the monster and the battle will last infinitely. Otherwise, print the positive integer kk such that kk is the first minute after which the monster is dead.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=+;
const ll INF = 0x3f3f3f3f3f3f3f3f;
int t,n,m,k,q;
unsigned long long ans;
ll cnt,flag,temp,sum;
ll h;
int a[N];
int main()
{
cin>>h>>n;
ll H=h;
ll minl=INF;
for(int i=;i<=n;i++){
cin>>a[i];
sum+=a[i];
minl=min(minl,sum);
if(h+sum<=){//如果h加上第一轮的sum小于0,就输出sum值所在下标
cout<<i<<endl;
return ;
}
}
if(minl>=||sum>=){// 和最小序列为正数或一轮所有值的和为正数,输出-1,代表不能实现将hp扣为0及一下
cout<<-<<endl;
return ;
}
cnt=(H+minl)/-sum;//hp加上和最小序列后除-sum得整数轮数,为n-2 或n-1 ,取决于数是到 和最小序列最后一个,还是之前就使hp<=0
if((H+minl)%-sum)//正好最大负值+整数个sum使hp=0
cnt++; //为n-1 或n
ans=(unsigned long long)cnt*n;//轮数乘以每轮个数
h=H+sum*cnt;
if(h<=){ //和最小序列和sum相等,即正好整数个sum使h<=0
cout<<ans<<endl;
return ;
}
for(int i=;i<=n;i++){//累加最后一轮
h+=a[i];
if(h<=){
cout<<ans+i<<endl;
return ;
}
}
}
题意分析:输入一个整数H,代表血量,每一轮的攻击消耗血量或增加血量,求消耗完时是第多少次攻击。
Codeforces1141E(E题)Superhero Battle的更多相关文章
- 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 ...
- 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 ...
- CF1141E Superhero Battle
A superhero fights with a monster. The battle consists of rounds, each of which lasts exactly n minu ...
- E. Superhero Battle
链接 [https://codeforces.com/contest/1141/problem/E] 题意 怪物开始的生命值,然后第i分钟生命值的变化 问什么时候怪物生命值为非正 分析 有一个巨大的坑 ...
- The 2015 China Collegiate Programming Contest -ccpc-c题-The Battle of Chibi(hdu5542)(树状数组,离散化)
当时比赛时超时了,那时没学过树状数组,也不知道啥叫离散化(貌似好像现在也不懂).百度百科--离散化,把无限空间中无限的个体映射到有限的空间中去,以此提高算法的时空效率. 这道题是dp题,离散化和树状数 ...
- 【CF1141E】Superhero Battle
\[x*p\ge y\rightarrow x=\lfloor{{y-1}\over p}\rfloor+1\]
- 【Codeforces 1141E】Superhero Battle
[链接] 我是链接,点我呀:) [题意] 题意 [题解] 二分最后轮了几圈. 二分之后直接o(N)枚举具体要多少时间即可. 注意爆long long的情况. 可以用对数函数,算出来有多少个0 如果大于 ...
- 南阳ccpc C题 The Battle of Chibi && hdu5542 The Battle of Chibi (树状数组优化+dp)
题意: 给你一个长度为n的数组,你需要从中找一个长度为m的严格上升子序列 问你最多能找到多少个 题解: 我们先对原序列从小到大排序,排序之后的序列就是一个上升序列 这里如果两个数相等的话,那么因为题目 ...
- 南阳ccpc C题 The Battle of Chibi 树状数组+dp
题目: Cao Cao made up a big army and was going to invade the whole South China. Yu Zhou was worried ab ...
随机推荐
- 最新版navicat 12.1 破解(Keygen注册机)
最新注册机链接:https://pan.baidu.com/s/1fFCRkkXMzk6CFpbttCDr7w 提取码:40xo 1.下载安装Navicat 在Navicat关闭的情况下运行注册机 ...
- c++ 更新 performance counter 数据,错误码 87
ERROR_INVALID_PARAMETER 87 (0x57) The parameter is incorrect. 很可能是该送 ULONG 的送了 ULONGLONG,vise versa
- 【linux题目】第三关
1. 解释下什么是GPL,GNU,自由软件? 2. 如何选择Linux操作系统版本? 3. 安装系统时如何给Linux操作系统分区? 4. 描述Linux系统的启动过程? 5. 简要说出20个Linu ...
- certutil 导入 CA 证书
2019独角兽企业重金招聘Python工程师标准>>> 在linux下使用GoAgent客户端的时候,需要导入CA.cer证书. 安装证书管理工具 apt-get install l ...
- js的同步与异步
JavaScript语言的一大特点就是单线程,也就是说,同一个时间只能做一件事.那么,为什么JavaScript不能有多个线程呢?这样能提高效率啊. JavaScript的单线程,与它的用途有关.作为 ...
- 上传组件Fine Uploader在ASP.NET中的应用
现如今,世面上流行着许多前端上传组件,例如:Uploadify(http://www.uploadify.com/),Fine Uploader,等等.这篇博客从头开始,介绍如何在ASP.NET MV ...
- ubuntu 使用 vsftpd 基于系统用户配置相互隔离的 ftp (ftps) 服务
我们在日常使用 UbuntuServer 服务器时,经常会直接使用基于 ssh 的 sftp 连接服务器直接进行文件上传和下载,不过这个方式其实有一定的安全隐患,当一个团队有多个人员,需要连接服务器 ...
- 10)drf 过滤器(条件查询 排序 ) 分页器
一.群查接口各种筛选组件 数据准备 models.py class Car(models.Model): name = models.CharField(max_length=16, unique=T ...
- FarmCraft
题意:mhy住在一棵有n个点的树的1号结点上,每个结点上都有一个妹子.mhy从自己家出发,去给每一个妹子都送一台电脑,每个妹子拿到电脑后就会开始安装zhx牌杀毒软件,第i个妹子安装时间为ci.树上的每 ...
- FastDFS文件服务器安装指南附安装包和自启动(看此篇就够了)
安装包在最后,本文为博主自己亲自安装记录 转载请注明出处 注意文字不清晰请放大看,放大看!! 安装包地址