题意:

有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. kubernetes的Kubelet

    1. kubelet简介 在kubernetes集群中,每个Node节点都会启动kubelet进程,用来处理Master节点下发到本节点的任务,管理Pod和其中的容器.kubelet会在API Ser ...

  2. selenium+iframe 如何定位元素(实战)

    场景: 在同一界面,需定位iframe里面的元素, 就需要切换至Iframe块,然后定位元素,验证完成后,再切换出来. 如果不切换至iframe ,会发现不管采取什么定位,都会报元素不存在.

  3. P4491 [HAOI2018]染色

    题目链接:洛谷 题目大意:$n$个位置染$m$种颜色,如果出现次数恰为$S$次的颜色有$k$种,则对答案有$W_k$的贡献,求所有染色方案的答案之和$\bmod 1004535809$. 数据范围:$ ...

  4. WCF访问超时:HTTP 请求已超过xx:yy分配的超时。为此操作分配的时间可能是较长超时的一部分。

    在服务端设置时间长些 <client> <endpoint address="http://43.98.49.189:5700/UPJWCFServcie.svc" ...

  5. php 的函数

    一.函数定义及变量作用域 1. 函数的声明和调用 函数的目的是复用. [$variable=] function [name]([$param]){} 2. 变量的作用域 (1) 全局变量 函数内部想 ...

  6. MATLAB中产生随机数的那些函数

    1.产生从imin~imax的m*n矩阵 randi([imin,imax],m,n); 2.产生1~n的无重复随机整数 randperm(n);

  7. python练习题-day1

    1.使用while循环输入 1 2 3 4 5 6     8 9 10 count=0 while count<10: count+=1 if count==7: continue print ...

  8. centos who命令 查看当前登录系统用户信息

    who 显示当前登录系统的用户,但w显示的更为详细 默认输出 [root@mysql ~]# who //用户名.登录终端.登录时间 root pts/ -- : (192.168.0.110) -a ...

  9. OC动画CABasicAnimation

    //1.创建动画 CABasicAnimation *anima=[CABasicAnimation animationWithKeyPath:@"bounds"]; //1.1设 ...

  10. CentOS 7 :Failed to start IPv4 firewall with iptables.

    用iptables开启防火墙报错: Failed to start  IPv4 firewall with iptables. 转载于:https://blog.csdn.net/ls1645/art ...