题意:

有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. 分布式任务队列Celery入门与进阶

    一.简介 Celery是由Python开发.简单.灵活.可靠的分布式任务队列,其本质是生产者消费者模型,生产者发送任务到消息队列,消费者负责处理任务.Celery侧重于实时操作,但对调度支持也很好,其 ...

  2. Docker 镜像(五)

    我们都知道,操作系统分为内核和用户空间.对于 Linux 而言,内核启动后,会挂载 root 文件系统为其提供用户空间支持.而 Docker 镜像(Image),就相当于是一个 root 文件系统.比 ...

  3. Verilog如何从外部更改模块内参数

    例如有一个模块 module x(a,b,c); input a,b; output c; 'd0, h=9'd3; ...... endmodule 两种解决方法: 1.使用带有参数值的模块实例语句 ...

  4. mysql-utilities1.6

    mysql-utilities1.6 mysql-utilities是一个用python编写的mysql工具集 mysql-utilities是Oracle专门开发的 一共有28个工具 /usr/bi ...

  5. what's the python之函数及装饰器

    what's the 函数? 函数的定义:(return是返回值,可以没有,不过没有的话就返回了None) def wrapper(参数1,参数2,*args,默认参数,**kwargs): '''注 ...

  6. 香港低价linux虚拟主机,

    https://www.sugarhosts.com/zh-cn/hosting/shared-web-hosting Shared Baby 36 个月 ¥ 26.99 19 99 · / 月 续费 ...

  7. 八种排序算法--java实现(转)

    (转:http://blog.csdn.net/without0815/article/details/7697916) 8种排序之间的关系: 1, 直接插入排序 (1)基本思想:在要排序的一组数中, ...

  8. BI-LSTM and CRF using Keras

    问题1:CUDA_ERROR_OUT_OF_MEMORY: How to activate multiple GPUs from Keras in Tensorflow import keras.ba ...

  9. k8s pv 的三种挂载模式

    ReadWriteOnce:可读可写,只能被一个Node节点挂载 ReadWriteMany:可读可写,可以被多个Node节点挂载 ReadOnlyMany:只读,能被多个Node节点挂载

  10. [LeetCode] 124. Binary Tree Maximum Path Sum_ Hard tag: DFS recursive, Divide and conquer

    Given a non-empty binary tree, find the maximum path sum. For this problem, a path is defined as any ...