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入门详细教程(五)
前言 本篇紧接着spring入门详细教程(三),建议阅读本篇前,先阅读第一篇,第二篇以及第三篇.链接如下: Spring入门详细教程(一) https://www.cnblogs.com/jichi/ ...
- xxx.jar或者xxx.war中没有主清单属性和spring-boot-maven-plugin的作用
因为springboot本身集成了tomcat插件,所以我们可以直接使用mvn clean package命令打成jar包或者war包,然后使java -jar xxx.jar 或者 java -ja ...
- 7. svg学习笔记-图案和渐变
之前,我们仅仅使用纯色来为图形填充颜色和绘制轮廓,除此之外,我们还可以使用图案和渐变来填充图形或者是绘制轮廓. 图案 图案的效果类似于,在网页中给一个元素指定背景图像,当背景图像的尺寸小于元素的尺寸的 ...
- C# -- 抽象类与抽象方法
C#: 抽象类与抽象方法 1.代码 class Program { static void Main(string[] args) { ; i < ; i++) { == ) { Storage ...
- CISCO 动态路由(OSPF)
OSPF(开放式最短路径优先):是一个内部网关协议(Interior Gateway Protocol,简称IGP),用于在单一自治系统(autonomous system,AS)内决策路由.是对链路 ...
- 英语初级学习系列-00-Hello-打招呼
开场白 当二咪过生日的时候,作为主人公(host)该如何开场呢? 1. Good evening, ladies and gentlemen. 先生们女士们,晚上好. 2. Welcome to my ...
- Node爬虫之初体验
记得之前就听说过爬虫,个人初步理解就是从网页中抓取一些有用的数据,存储到本地,今天就当是小牛试刀,拿来溜溜...... 实现需求: 抓取课程数据,输入url后并在浏览器端以一定的数据格式显示出来(如下 ...
- 【夯实PHP基础】PHPUnit -- PHP测试框架
本文地址 分享提纲: 1.概述 2.安装 3.编写第一个测试用例 4.PHPUnit高级 5.参考 1.概述 1)[测试框架] 它是一款轻量级的PHP测试框架,是一个xUnit的体系结构的单元测试框架 ...
- Thread.currentThread()和this的区别——《Java多线程编程核心技术》
前言:在阅读<Java多线程编程核心技术>过程中,对书中程序代码Thread.currentThread()与this的区别有点混淆,这里记录下来,加深印象与理解. 具体代码如下: pub ...
- 笔记-Android中打开各种格式的文件(apk、word、excel、ppt、pdf、音视频、图片等)
打开后缀.apk的文件.即启动安装程序. //apkFilePath 文件路径 public void installAPK(String apkFilePath) { // 创建URI Uri ur ...