题意:

有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. linux 源码安装 mono

    $ yum install bison gettext glib2 freetype fontconfig libpng libpng-devel libX11 libX11-devel glib2- ...

  2. 关于javascript中defineProperty的学习

    语法 Object.defineProperty(obj, prop, descriptor) 参数 obj 要在其上定义属性的对象. prop 要定义或修改的属性的名称. descriptor 将被 ...

  3. NOIP观光公交

    #include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #inc ...

  4. 从EnableJpaRepositories说开去

    1 .spring boot @EnableJpaRepositories( repositoryBaseClass = BaseRepositoryImpl.class, includeFilter ...

  5. VS Code 创建代码段 Snippets

    菜单:文件 -> 首选项 -> 用户代码片断 打开User Snippets菜单: 选择C#: 然后把里面注释的文字留下, 复制其中那段代码并修改称自己的代码段: "Create ...

  6. 多线程下的单例-double check

    话不多说直接上代码: public sealed class Singleton { private static Singleton _instance = null; // Creates an ...

  7. Learn nodejs: Tutorials for Programmers of All Levels, 程序员每个阶段的示例

    https://stackify.com/learn-nodejs-tutorials/ What is Node.js? Node.js can be defined as a dynamic, c ...

  8. 2019.03.30 图解HTTP

    文章来源<图解HTTP> 第一章 了解Web及网络基础 你有想过当你在浏览器(web browser)的地址栏上输入URL时,Web页面是如何实现的吗? 嗯,好像也没想过 web使用一种名 ...

  9. HttpwebRequest - 带ViewState的网页POST请求

    这是我今天下午碰到的案例,一个退订页面的post请求,请求头信息都很明确,but看看下面这个请求体,除了最后一个key是我的页面控件名称,其他的几个ViewState相关都是what呢?(ViewSt ...

  10. python threading acquire release

    线程同步 //test.py import threading import time exitFlag = 0 class myThread (threading.Thread): def __in ...