【链接】 我是链接,点我呀:)

【题意】

题意

【题解】

二分最后轮了几圈。
二分之后直接o(N)枚举具体要多少时间即可。
注意爆long long的情况。
可以用对数函数,算出来有多少个0
如果大于17直接缩小点就好。

【代码】

#include <bits/stdc++.h>
#define ll long long
using namespace std; const int N = 2e5; ll H,a[N+10];
int n; int main(){
ios::sync_with_stdio(0),cin.tie(0);
cin >> H >> n;
for (int i = 1;i <= n;i++) cin >> a[i];
for (int i = 2;i <= n;i++) a[i]+=a[i-1];
for (int i = 1;i <= n;i++)
if (a[i]<=-H){
cout<<i<<endl;
return 0;
}
if (a[n]>=0){
cout<<-1<<endl;
return 0;
}
ll ans = 1e18;
ll l = 0,r = 1e12,temp=-1;
while (l<=r){
ll mid = (l+r)/2;
ll T1 = log10(mid+1);
ll T2 = log10(abs(a[n])+1);
if (T1+T2>=17){
r = mid-1;
continue;
}
ll rest = H-mid*abs(a[n]),temp1 = -1;
if (rest<=0)
temp1 = mid*n;
else
for (int i = 1;i <= n;i++){
if (a[i]+rest<=0){
temp1 = i + mid*n;
break;
}
}
if (temp1==-1){
l = mid + 1;
}else{
temp = temp1;
r = mid - 1;
}
}
cout<<temp<<endl;
return 0;
}

【Codeforces 1141E】Superhero Battle的更多相关文章

  1. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  2. 【Codeforces 567D】One-Dimensional Battle Ships

    [链接] 我是链接,点我呀:) [题意] 长度为n的一个序列,其中有一些部分可能是空的,一些部分是长度为a的物品的一部分 (总共有k个长度为a的物品,一个放在位置i长度为a的物品会占据i,i+1,.. ...

  3. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  4. 【27.66%】【codeforces 592D】Super M

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  5. 【codeforces 707E】Garlands

    [题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...

  6. 【codeforces 707C】Pythagorean Triples

    [题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...

  7. 【codeforces 709D】Recover the String

    [题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...

  8. 【codeforces 709B】Checkpoints

    [题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...

  9. 【codeforces 709C】Letters Cyclic Shift

    [题目链接]:http://codeforces.com/contest/709/problem/C [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...

随机推荐

  1. Hadoop端口访问

    Hadoop集群默认端口 Hadoop本地开发,9000端口拒绝访问

  2. Educational Codeforces Round 24 E

    Vova again tries to play some computer card game. The rules of deck creation in this game are simple ...

  3. 在脚本中输入密码执行sudo,可关机等。

    如下,makexxx.sh make update-api make echo "password" | sudo -S shutdown -h now

  4. Nagios安装与部署

    Nagios概述: Nagios是一款开源免费(也有收费版的Nagios XI)的监控工具,可以用以监控Windows.Linux.Unix.Router.Switch,可以监控指定主机的物理基础资源 ...

  5. Apache Kylin的框架介绍

    不多说,直接上干货! Apache kylin 能提供低延迟(sub-second latency)的秘诀就是预计算,即针对一个星型拓扑结构的数据立方体,预计算多个维度组合的度量,然后将结果保存在hb ...

  6. Codeforces GYM 100741A . Queries

    time limit per test 0.25 seconds memory limit per test 64 megabytes input standard input output stan ...

  7. python的特殊数字类型(无穷大、无穷小等)

    float('inf') 表示正无穷 -float('inf') 或 float('-inf') 表示负无穷 其中,inf 均可以写成 Inf 起步python中整型不用担心溢出,因为python理论 ...

  8. laravel扩展包服务提供者的注册的两种方式

    一. 包自动发现 在 Laravel 应用的配置文件 config/app.php 中,providers 配置项定义了一个会被 Laravel 加载的服务提供者列表.当安装完新的扩展包后,在老版本中 ...

  9. DFS、BFS和Backtracking模板

    区别与联系 区别 DFS多用于连通性问题因为其运行思想与人脑的思维很相似,故解决连通性问题更自然,采用递归,编写简便(但我个人不这样觉得...) DFS的常数时间开销会较少.所以对于一些能用DFS就能 ...

  10. Vue的 $parent,并不能准确找到上一层的控件,所以如果需要,需要填坑这个 bug,递归寻找下上级

    Vue的 $parent,并不能准确找到上一层的控件,所以如果需要,需要填坑这个 bug,递归寻找下上级 // Find components upward function findComponen ...