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 ...
随机推荐
- 探索SQL Server元数据(二)
背景 上一篇中,我介绍了SQL Server 允许访问数据库的元数据,为什么有元数据,如何使用元数据.这一篇中我会介绍如何进一步找到各种有价值的信息.以触发器为例,因为它们往往一起很多问题. 那么如何 ...
- Elasticsearch深入搜索之结构化搜索及JavaAPI的使用
一.Es中创建索引 1.创建索引: 在之前的Es插件的安装和使用中说到创建索引自定义分词器和创建type,当时是分开写的,其实创建索引时也可以创建type,并指定分词器. PUT /my_index ...
- 记一次 MySQL semaphore crash 的分析(爱可生)
文章来源:爱可生云数据库作者:洪斌 DBA应该对InnoDB: Semaphore wait has lasted > 600 seconds. We intentionally crash t ...
- Windows Server 2016-WinSer 2016标准版与数据中心版的区别
今天在整理文章的时候看到有读者问到他现在的测试环境是用的Windows Server 2016标准版,和我现阶段系列文章的环境是否有区别. 其实针对Windows Server 2016 Active ...
- NumPy 中的集合运算
怎样快速找出两个数组中相同的元素? numpy.isin(element,test_elements,assume_unique = False,invert = False ) 计算test_ele ...
- IIS 部署问题 404
在部署IIS环境中,偶尔会遇到 404 错误,就算以前遇到过,也因为时间久了导致大概知道是什么错了,具体解决方案觉忘了,所以留下一个记录,留给自己,也是给大家一点提醒.(注:错误信息也懒得截图了,希望 ...
- C++_调用约束
1.要求 声明定义处调用约定必须相同 int __stdcall add(int a, int b); int __stdcall add(int a, int b) { return a + b; ...
- qt designer设置界面是label中文字与文本框对齐设置
往往在使用 qt designer布置界面时,添加的label和文本框中是直接从工具箱中拖进去的,由于每个控件尺寸大小不一,就会造成label中的文字相对于文本框比较较偏上,看下面未经调整的直接效果 ...
- Nginx使用教程(五):使用Nginx缓存之缓存静态内容
NGINX虽然已经对静态内容做过优化. 但在高流量网站的情况下,仍然可以使用open_file_cache进一步提高性能. NGINX缓存将最近使用的文件描述符和相关元数据(如修改时间,大小等)存储在 ...
- 设计模式のTemplatePattern(模板模式)----行为模式
一.产生背景 在程序设计中,可能每个对象都有共同的地方,而此时如果每个对象定义一次,如下例子,每个对象都写Stay()方法,这样在每个类中都有很多相同的代码,此时,我们需要用到模板设计模式,来解决这个 ...