题意:

有n个巫师站成一列,每个巫师有自己的血量。

一个人射箭攻击他们,每次造成若干点伤害,巫师按照给定的顺序承受伤害,如果伤害大了,那么死掉,伤害落到下一个巫师身上。

如果一轮攻击之后,所有的巫师都死了,那么他们会立即复活。

给出若干个询问,问每轮攻击之后还剩多少巫师活着。

思路:

前缀和加二分,每次伤害累加,大于了总和便归零且复活。

代码:

#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
const int N = 2e5 + ;
long long pre[N],a[N];
int main()
{
int n,q;
scanf("%d%d",&n,&q);
for (int i = ;i < n;i++)
{
scanf("%lld",&a[i]);
}
pre[] = a[];
for (int i = ;i < n;i++) pre[i] = a[i] + pre[i-];
long long ans = ;
for (int i = ;i < q;i++)
{
long long b;
scanf("%lld",&b);
ans += b;
if (ans >= pre[n-])
{
printf("%d\n",n);
ans = ;
}
else
{
int pos = lower_bound(pre,pre+n,ans) - pre;
long long gg = pre[pos];
int tt = ;
if (gg == ans)
{
tt = n - pos - ;
}
else
{
tt = n - pos;
}
printf("%d\n",tt);
}
}
return ;
}

codeforces 975C Valhalla Siege的更多相关文章

  1. [codeforce 975C] Valhalla Siege (二分)

    Examples input 5 5 1 2 1 2 1 3 10 1 1 1 output 3 5 4 4 3 input 4 4 1 2 3 4 9 1 10 6 output 1 4 4 1 N ...

  2. Codeforces Round #478 C. Valhalla Siege

    C. Valhalla Siege time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

  3. Codeforces-975C - Valhalla Siege 前缀和 思维

    C. Valhalla Siege time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

  4. Codeforces 975C

    题意略. 思路:这题考察的是二分搜索. #include<bits/stdc++.h> #define maxn 200005 using namespace std; typedef l ...

  5. Codeforces Round #478 Div2 975A 975B 975C 975D

    A. Aramic script 题目大意:   对于每个单词,定义一种集合,这个集合包含且仅包含单词中出现的字母.给你一堆单词,问有多少种这种集合. 题解:   状压,插入set,取size #in ...

  6. Codeforces Round #478 (Div. 2)

    题目链接:http://codeforces.com/contest/975 A. Aramic script time limit per test:1 second memory limit pe ...

  7. Codeforces Round #478 (Div. 2) ABCDE

    A. Aramic script time limit per test 1 second memory limit per test 256 megabytes input standard inp ...

  8. CF练习记录

    2018/5/6 Codeforces Round #478 (Div. 2) C http://codeforces.com/contest/975/problem/C Valhalla Siege ...

  9. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

随机推荐

  1. java 随机抽取案例,不重复抽取

    以学生类为例,先准备一个Student类 package cn.sasa.demo1; public class Student { private int id; private String na ...

  2. 嵌入式Qt4.8.0支持ttf字库,并显示中文

    引言 最近在做QT项目发现中文没法显示,于是百度QT嵌入式显示中文,基本上提示的都是把ttf字库转换为QPF(QT专门支持二进制的),发现这个qpf本身制作就很麻烦,按照网上的做法实实在在来了一边,发 ...

  3. Machine Learning in action --LogisticRegession 逻辑回归

    本系列主要参考<机器学习实战>,使用python3编译环境,实现书中的相关代码. 1.基本算法 关于梯度上升算法和随机梯度上升算法的选择: 当数据集较小时,使用梯度上升算法: 当数据集较大 ...

  4. laravel出现No hint path defined for [sudosu]的解决方法

    今天ytkah在部署laravel项目时出现了No hint path defined for [sudosu]的问题,大概意思是没有定义sudosu的提示路径,那我们找一下配置文件有没相关设置,看到 ...

  5. 微信公开课厦门站 时尚行业专场PPT

    做为一位开发者,ytkah有幸参加了微信公开课厦门站-时尚行业专场,见证了微信支付的发展历程,小程序产品的实力简介,感受了一下与各位高手共聚一堂的氛围,当然还近距离接触了著名主持人兼NPC潮品(与潘玮 ...

  6. 报错解决——Disconnected:No supported authentication methods available

    该问题是由于ssh链接未允许远程密码认证导致的 解决方法 通过管理控制台进入系统,查看 /etc/ssh/sshd_config配置文件中是否包含以下配置 PasswordAuthentication ...

  7. 如何卸载docker

    1.卸载 (1)yum remove docker \ docker-client \ docker-client-latest \ docker-common \ docker-latest \ d ...

  8. Python random模块random/uniform/randint/choice/getrandbits/shuffle/choice/sample随机函数

    1.random.random() 返回0<=n<1之间的随机实数n 2. random.uniform() 弥补了上面函数的不足,它可以设定浮点数的范围,一个是上限,一个是下限. 3. ...

  9. Hybrid设计--账号体系的建设

    前后端分离:开发效率高,没有SEO 现在是重客户端设计:交互和业务逻辑是前端来写,适合做前后端分离.对前端更友好,提高了效率. 传统模式开发:整个业务逻辑是server端写,不适合做前后端分离.ser ...

  10. Go http server 高并发

    先来个段子:[并发处理连接数] 多高? 很高! 到底多高? 没有一亿,都算少了! . . . 然后就没有然后了... “段子 END” 这就是目前中国企业的通病:提个概念,没有答案,最后造成概念也模糊 ...