E. Superhero Battle Codeforces Round #547 (Div. 3) 思维题
2 seconds
256 megabytes
standard input
standard output
A superhero fights with a monster. The battle consists of rounds, each of which lasts exactly nn minutes. After a round ends, the next round starts immediately. This is repeated over and over again.
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.
1000 6
-100 -200 -300 125 77 -4
9
1000000000000 5
-1 0 0 0 0
4999999999996
10 4
-3 -6 5 4
-1 这个题目不难,但是细节比较多,我觉得我做的很自闭,因为WA好多次,然后我就自闭了。
上网查了查题解,就是要考虑一次循环之后可以减少最多的值,这个要优先考虑,然后就是去找有多少个整次的循环。
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <iostream>
#include <vector>
#include <queue>
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
const int maxn = 2e5 + ;
ll a[maxn]; int main()
{
int flag=,mark;
ll h, n,sum=,mi=inf;
cin >> h >> n;
ll g = h;
for(int i=;i<=n;i++)
{
scanf("%lld", &a[i]);
sum += a[i];
mi = min(mi, sum);
g += a[i];
if(g<=&&!flag)
{
mark = i;
flag = ;
}
}
if(flag)
{
printf("%d\n", mark);
return ;
}
if (sum >= )
{
printf("-1\n");
return ;
}
sum = -sum;
h += mi;
ll ans = h / sum * n;
ll cur = h % sum - mi;
while(cur>)
{
for(int i=;i<=n;i++)
{
cur += a[i];
ans++;
if (cur <= ) break;
}
//printf("cur=%d\n", cur);
}
printf("%lld\n", ans);
return ;
}
E. Superhero Battle Codeforces Round #547 (Div. 3) 思维题的更多相关文章
- C. Nice Garland Codeforces Round #535 (Div. 3) 思维题
C. Nice Garland time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...
- Codeforces Round #547 (Div. 3) 题解
Codeforces Round #547 (Div. 3) 题目链接:https://codeforces.com/contest/1141 A,B咕咕了... C. Polycarp Restor ...
- Codeforces Round #378 (Div. 2) D题(data structure)解题报告
题目地址 先简单的总结一下这次CF,前两道题非常的水,可是第一题又是因为自己想的不够周到而被Hack了一次(或许也应该感谢这个hack我的人,使我没有最后在赛后测试中WA).做到C题时看到题目情况非常 ...
- Codeforces Round #612 (Div. 2) 前四题题解
这场比赛的出题人挺有意思,全部magic成了青色. 还有题目中的图片特别有趣. 晚上没打,开virtual contest打的,就会前三道,我太菜了. 最后看着题解补了第四道. 比赛传送门 A. An ...
- Codeforces Round #552 (Div. 3) A题
题目网址:http://codeforces.com/contest/1154/problem/ 题目意思:就是给你四个数,这四个数是a+b,a+c,b+c,a+b+c,次序未知要反求出a,b,c,d ...
- Codeforces Round #713 (Div. 3)AB题
Codeforces Round #713 (Div. 3) Editorial 记录一下自己写的前二题本人比较菜 A. Spy Detected! You are given an array a ...
- 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 ...
- Codeforces Round #412 Div. 2 补题 D. Dynamic Problem Scoring
D. Dynamic Problem Scoring time limit per test 2 seconds memory limit per test 256 megabytes input s ...
- Codeforces Round #547 (Div. 3) E. Superhero Battle (数学)
题意:有一个HP为\(h\)的大怪兽,你需要轮流进行\(i\)次操作.每次可以使\(h+=d_i\)(\(d_i\)有正有负),当第\(n\)次操作完成后,再从第一次开始,问能否使得怪兽的HP变为\( ...
随机推荐
- C# CLR via 对象内存中堆的存储【类型对象指针、同步块索引】
最近在看书,看到了对象在内存中的存储方式. 讲到了对象存储在内存堆中,分配的空间除了类型对象的成员所需的内存量,还有额外的成员(类型对象指针. 同步块索引 ),看到这个我就有点不懂了,不知道类型对象指 ...
- JSJ—编译器与虚拟机哪个重要?
阅读本文约“2分钟” 熟悉Java的朋友都知道虚拟机还有编译器,那么它们各自主要的功能是什么?谁比较重要呢?让我们来了解一下这两位美女的故事. 虚拟机可以说就是Java,她能让程序运行起来. 但是编译 ...
- 我永远喜欢着OOP——第一次总结
我永远喜欢着OOP--第一次总结 一.三次作业总结分析 1. 第一次作业 1.1 作业分析 第一作业主要是给我们引入了一个对于非法输入处理的思想,包括第一次上机,都一直围绕着一个全新的主题,就是非法输 ...
- thinkphp——通过在线编辑器添加的内容在模板里正确显示(只显示内容,而不是html代码)
thinkphp编辑器回显问题如下: 解决办法如下: 对于编辑器发布的内容,前台模板显示为html的解决办法是: 在模板输出字段加入html_entity_decode()函数 也就是:PHP输出时的 ...
- js 人民币小写金额转换为大写
function smalltoBIG(n) { var fraction = ['角', '分']; var digit = ['零', '壹', '贰', '叁', '肆', '伍', '陆', ...
- MySQL服务无法启动 3534
1.环境变量配置完成 2.配置文件编辑完成 3.启动服务(启动不成功,错误信息“MySQL服务无法启动 请键入 NET HELPMSG 3534 以便获得更多的帮助”) 错误原因:mysql安装目录下 ...
- Python date,datetime,time等相关操作总结
date,datetime,time等相关操作总结 by:授客 QQ:1033553122 测试环境: Python版本:Python 3.3.2 代码实践: __author__ = '授客' ...
- AS插件-GsonFormat
支持 field 类型的修改. 支持快捷键打开 GsonFormat ,默认为 option+s(mac), alt+s(win) 支持 field 名称的修改. 支持添加 field 前缀. 支持多 ...
- (办公)Mysql入门
数据库的操作:1.用 SHOW 显示已有的数据库show databases 2.创建数据库:create database 创建数据库create database db_name3.删除数据库:d ...
- javascript的介绍、javascirpt的存在形式、javascript注释
本文内容: javascript的介绍 javascirpt的存在形式 javascript注释 javascript的介绍: javascript是一种解释性脚本语言 它的用途是给html网页增加动 ...