【Codeforces 1141E】Superhero Battle
【链接】 我是链接,点我呀:)
【题意】
题意
【题解】
二分最后轮了几圈。
二分之后直接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的更多相关文章
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 567D】One-Dimensional Battle Ships
[链接] 我是链接,点我呀:) [题意] 长度为n的一个序列,其中有一些部分可能是空的,一些部分是长度为a的物品的一部分 (总共有k个长度为a的物品,一个放在位置i长度为a的物品会占据i,i+1,.. ...
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- 【27.66%】【codeforces 592D】Super M
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【codeforces 707E】Garlands
[题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...
- 【codeforces 707C】Pythagorean Triples
[题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...
- 【codeforces 709D】Recover the String
[题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...
- 【codeforces 709B】Checkpoints
[题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...
- 【codeforces 709C】Letters Cyclic Shift
[题目链接]:http://codeforces.com/contest/709/problem/C [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...
随机推荐
- curry柯里化函数实现
curry柯里化函数实现 参考文章: 一行写出javascript函数式编程中的curry 感谢作者分享 第一步: 缓存原始函数的参数个数 function curry(fn) { var limit ...
- 【转载】(0, eval)(‘this’)
var window = this || (0, eval)('this') 在avalon源码中有这么一行代码,var window = this很容易理解 这里复习一下Global Object: ...
- Saltstack学习笔记--安装
实验环境: 两台RHEL 7.2 192.168.75.135 master .minion 192.168.75.136 minion 确保机器的防火墙及seli ...
- 微服务熔断限流Hystrix之流聚合
简介 上一篇介绍了 Hystrix Dashboard 监控单体应用的例子,在生产环境中,监控的应用往往是一个集群,我们需要将每个实例的监控信息聚合起来分析,这就用到了 Turbine 工具.Turb ...
- Intent实现界面跳转、程序跳转
一个程序往往由多个界面组成,界面之间的跳转,实质是Activity之间的跳转. 从当前程序跳转到其它程序,实质是启动了目标程序的入口Activity. Intent被称为意图,常用于组件之间的交互,可 ...
- 一些关于Spring的随笔
Spring的IOC.AOP IOC(Inversion of Control): spring容器控制了所有的bean,不用spring以前,一个bean要依赖另一个bean就在这个bean里初始化 ...
- Boxes And Balls(三叉哈夫曼编码)
题目 原题链接:http://codeforces.com/problemset/problem/884/D 现有一堆小石子,要求按要求的数目分成N堆,分别为a1.a2....an.具体的,每次选一个 ...
- jeecms标签
.@cms_content_list--新闻单页 [@cms_content channelId=' dateFormat='MM-dd' ] [#if tag_list?size>0] < ...
- env - 在重建的环境中运行程序
SYNOPSIS(总览) env [OPTION]... [-] [NAME=VALUE]... [COMMAND [ARG]...] DESCRIPTION(描述) 设置环境中的每个NAME为VAL ...
- Unexpected Exception caught setting 'username' on 'class com.bj186.crm.web.action.UserAction: Error setting expression 'username' with value ['艾格尼丝', ]
问题场景: 在使用表单向Action传递数据的时候, 遇到了这个问题, 导致了空指针异常. 问题描述: 10:14:56.622 [http-nio-8080-exec-45] ERROR com.o ...