【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 #261 (Div. 2) A
Description Pashmak has fallen in love with an attractive girl called Parmida since one year ago... ...
- 使用 Realm 和 Swift 创建 ToDo 应用
原文出处: HOSSAM GHAREEB 译文出处:Prayer’s blog(@EclipsePrayer) 智能手机的快速发展的同时,涌现出了很多对开发者友好的开发工具,这些工具不仅使得开发变 ...
- Oracle及其相关软件历史版本下载地址
https://edelivery.oracle.com/osdc/faces/Home.jspx 打开上面这个链接,输入自己或可用的帐号即可. 搜索到自己想要下载的软件后,点击,软件会添加到购物车中 ...
- Python打开目录下所有文件
用Python打开指定目录下所有文件,统计文件里特定的字段信息. 这里是先进入2017-02-25到2017-03-03目录,然后进入特定IP段目录下,最后打开文件进行统计 import os, gl ...
- [ SNOI 2013 ] Quare
Description 题目链接 求一张无向带权图的边双连通生成子图的最小代价. Solution 核心的思路是,一个点双连通分量肯定是一堆环的并. 考虑增量地构造这个边双连通图,每次把一个环并进去, ...
- js事件、Js中的for循环和事件的关系、this
一.js事件 1.事件 用户在网页中所触发的行为 鼠标滑动种类很多,键盘.表单特列: 点击:onclick 鼠标进入:onmouseenter 鼠标离开:onmouseleave 鼠标悬浮:onmo ...
- 新手玩CSS中的一些黑科技
哎哎 1.鼠标移进网页里,不见了= = *{ cursor: none!important; } 2.简单的文字模糊效果 *{ color: transparent; text-shadow: #11 ...
- ASP.NET Web API FilterAttribute假想
偶然的测试发现API FilterAttribute没用引用只会初始化一次 比如: 如果是 Global Action Filter, 则全局只会初始化一次 针对于不同的Controller级别的Ac ...
- sql格式化工具
桌面版: SQLInform: http://www.sqlinform.com/download_free_desktop_sw.html 在线格式化: http://www.dpriver.com ...
- UGUI世界坐标转换为UI本地坐标
以下是实现hud跟随3D物体的脚本,只是测试用,不是开发中的代码,脚本挂在任意游戏物体上 demo下载 using UnityEngine; public class SceneFollowUI : ...