【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 [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...
随机推荐
- 贪心 Codeforces Round #297 (Div. 2) C. Ilya and Sticks
题目传送门 /* 题意:给n个棍子,组成的矩形面积和最大,每根棍子可以-1 贪心:排序后,相邻的进行比较,若可以读入x[p++],然后两两相乘相加就可以了 */ #include <cstdio ...
- JAVA常用知识总结(三)——JAVA虚拟机
先附一张JAVA虚拟机内存结构图: 其中JAVA虚拟机的线程问题<为什么JAVA虚拟机分为线程共享和非线程共享?>一文中已经有详细介绍,本文从面试中常问的一些JAVA虚拟机问题出发,主要从 ...
- vs2013转为vs2010项目
1.首先用记事本之类的工具打开.sln文件 打开后会看到如下信息 Format Version 12.00 就是指VS2013 VisualStudioVersion = 12.0.21005.1 指 ...
- 浅议block实现原理,block为什么使用copy关键字?
1.block是一个特殊的oc对象,建立在栈上,而不是堆上,这么做一个是为性能考虑,还有就是方便访问局部变量. 2.默认Block使用到的局部变量会被copy,而不是retain.所以,他无法改变局部 ...
- Git之远程项目克隆到本地配置
远程代码克隆到本地工作区,需要进行简单的配置,用于识别身份 1.git config --global user.name [设置用户名,你的github用户名] 2.git config -- ...
- Haproxy+Rabbitmq中的问题
问题一.Rabbitmq集群搭建完成 某个集群节宕机后 无法添加失败 解决办法:停掉所有Rabbitmq服务 并删除集群文件C\Users\Administrator\AppData\Roaming\ ...
- java实现课堂随机点名小程序
通过jdbc连接数据库实现读取学生花名册进行随机点名! ~jdbc连接mysql数据库 || 注释部分代码可通过读取.txt文档实现显示学生信息 ~通过点击开始按钮实现界面中间标签不断更新学生信息 ...
- iOS 利用UIWebView与JavaScript交互的最简单办法
这里说的是针对iOS的!并且方法很简单!!并且验证可行的!!! 1, UIWebView调用 JavaScript 的函数: NSString* strValue = [webView stringB ...
- EEPROM介绍
EEPROM( Electrically Erasable Programmable Read Only Memory )全称是电气可擦除可编程只读存储器,是非易失存储器,可以访问到每个字节,容量比较 ...
- ubuntu下安装mongo扩展
安装openssl apt-get install openssl libssl-dev libssl0.9.8 libgtk2.0-dev 安装php-pear apt-get install ph ...