E. Superhero Battle
链接
[https://codeforces.com/contest/1141/problem/E]
题意
怪物开始的生命值,然后第i分钟生命值的变化
问什么时候怪物生命值为非正
分析
有一个巨大的坑
其实是很简单的一个题
可我还是跳了进去很多次
对于超过n的特别注意就行了
算是经典贪心吧
看代码吧
代码
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N=2e5+10;
ll d[N];
ll sum;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
ll H;
//freopen("in.txt","r",stdin);
while(cin>>H>>n){
sum=0;
ll cur=H,mi=1e17;
bool flag=0;
ll ans;
for(int i=1;i<=n;i++)
{
cin>>d[i]; sum+=d[i];
mi=min(mi,sum);
H+=d[i];
if(!flag&&H<=0) {
ans=i; flag=1;
}
}
if(flag){
cout<<ans<<endl;
}
else if(sum>=0){
cout<<-1<<endl;
}
else{
cur+=mi;
ans=(cur)/(-sum)*n;
ll mo=cur%(-sum);
ll k=mo-mi;
ll cnt=0;
while(k>0){
for(int i=1;i<=n;i++)
{
k+=d[i];
cnt++;
if(k<=0) break;
}
}
//cout<<ans<<' '<<cnt<<endl;
cout<<ans+cnt<<endl;
}
}
return 0;
}
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 ...
- Codeforces1141E(E题)Superhero Battle
A superhero fights with a monster. The battle consists of rounds, each of which lasts exactly nn min ...
- 【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 如果大于 ...
- Codeforces Round #547 (Div. 3) E. Superhero Battle (数学)
题意:有一个HP为\(h\)的大怪兽,你需要轮流进行\(i\)次操作.每次可以使\(h+=d_i\)(\(d_i\)有正有负),当第\(n\)次操作完成后,再从第一次开始,问能否使得怪兽的HP变为\( ...
- Codeforces Round #547 (Div. 3) 题解
Codeforces Round #547 (Div. 3) 题目链接:https://codeforces.com/contest/1141 A,B咕咕了... C. Polycarp Restor ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
随机推荐
- spring-AOP(面向切面编程)-xml方式配置
AOP是针对面向对象编程的一种补充,有时使用面向对象不能很好完成一些额外的功能业务时,可以采用AOP来进行补充. AOP术语: 切面(Aspect) 切面是用于编写切面逻辑的一个类,这个类很类似于JD ...
- 爬虫入门实例:利用requests库爬取笔趣小说网
w3cschool上的来练练手,爬取笔趣看小说http://www.biqukan.com/, 爬取<凡人修仙传仙界篇>的所有章节 1.利用requests访问目标网址,使用了get方法 ...
- Python操作字典(dict)
一.字典定义 >>> dict={} 二.字典元素添加 >>> dict['性别']='男' >>> dict {'性别': '男'} >& ...
- SQL Server Browser探究
一.官网关于SQL SERVER Browser服务的解释(谷歌翻译后稍作修改的): https://docs.microsoft.com/en-us/sql/tools/configuration- ...
- sed:-e 表达式 #1,字符 10:未终止的“s”命令
执行shell脚本时,使用sed变量替换指定的字符串,一直出现这个错误: [root@bqh-118 scripts]# vim while_rz.sh [root@bqh-118 scripts]# ...
- python opencv SIFT,获取特征点的坐标位置
备注:SIFT算法的实质是在不同的尺度空间上查找关键点(特征点),并计算出关键点的方向.SIFT所查找到的关键点是一些十分突出,不会因光照,仿射变换和噪音等因素而变化的点,如角点.边缘点.暗区的亮点及 ...
- 一个好看的php验证码源码
<?php $w = 80; //设置图片宽和高 $h = 26; $str = Array(); //用来存储随机码 $string = "ABCDEFGHIJKLMNOPQ ...
- Kafka consumer group位移0ffset重设
本文阐述如何使用Kafka自带的kafka-consumer-groups.sh脚本随意设置消费者组(consumer group)的位移.需要特别强调的是, 这是0.11.0.0版本提供的新功能且只 ...
- spring boot 的maven设置阿里云仓库
<build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> ...
- 【CQOI2011】放棋子
[CQOI2011]放棋子 在一个n行m列的棋盘里放一些彩色的棋子,使得每个格子最多放一个棋子,且不同颜色的棋子不能在同一行或者同一列.有多少种方法? 例如\(,n=m=3\),有两个白棋子和一个灰棋 ...