CodeForces 474B

Time Limit:1000MS Memory Limit:262144KB   64bit IO Format:%I64d & %I64u

Description

It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.

Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with numbers a1 + 1 to a1 + a2 and so on. See the example for a better understanding.

Mole can't eat all the worms (Marmot brought a lot) and, as we all know, Mole is blind, so Marmot tells him the labels of the best juicy worms. Marmot will only give Mole a worm if Mole says correctly in which pile this worm is contained.

Poor Mole asks for your help. For all juicy worms said by Marmot, tell Mole the correct answers.

Input

The first line contains a single integer n (1 ≤ n ≤ 105), the number of piles.

The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 103a1 + a2 + ... + an ≤ 106), where ai is the number of worms in the i-th pile.

The third line contains single integer m (1 ≤ m ≤ 105), the number of juicy worms said by Marmot.

The fourth line contains m integers q1, q2, ..., qm (1 ≤ qi ≤ a1 + a2 + ... + an), the labels of the juicy worms.

Output

Print m lines to the standard output. The i-th line should contain an integer, representing the number of the pile where the worm labeled with the number qi is.

Sample Input

Input

5
2 7 3 4 9
3
1 25 11

Output

1
5
3

Hint

For the sample
input:

  • The worms with labels from [1, 2] are in the first pile.
  • The worms with labels from [3, 9] are in the second pile.
  • The worms with labels from [10, 12] are in the third pile.
  • The worms with labels from [13, 16] are in the fourth pile.
  • The worms with labels from [17, 25] are in the fifth pile.
  • 题解:这道题如果只是读题很难完全懂,可以结合输入案例,就是第一行数据为5是行数,第二行数据为2,7,3,4,9,意思为排列的第一行有2个数,第二行有7个,以此类推,到第5行,第三行数据是输入要判断的数字的个数,第四行数据是输入要判断的数字,判断其所在行数。
  • 如下所示:
  • 1 2
  • 3 4 5 6 7 8 9
  • 10 11 12
  • 13 14 15 16 17
  • 18 19 20 21 22 23 24 25
  • 要判断案例中1,25 11所在的行数,首先可以建立一个数组,依次排列,把每一行都标记,第一行标记为1,以此类推,当输入一个数q时,输出a【q】,就可以得到所在的行数。
  • 标记时要注意其范围,标记完一行要进行+1,才可到达第二行。
#include<iostream>
using namespace std;
int a[];
int main()
{
int q,s,n,i,t,tot,f=;
while(cin>>n)
{
tot=;
for(int j=; j<=n; j++)
{
cin>>t;
for(i=tot; i<t+tot; i++)
a[i]=f;
f++;//每标记一次,f++,到达下一行
tot=i;
} cin>>q; for(i=; i<=q; i++)
{
cin>>s;
cout<<a[s]<<endl;//输入数字q,输出a【q】,得到的就是q所在的行 }
} return ;
}

CodeForces 474B(标记用法)的更多相关文章

  1. Codeforces 474B Worms 二分法(水

    主题链接:http://codeforces.com/contest/474/problem/B #include <iostream> #include <cmath> #i ...

  2. 版本控制之五:SVN trunk(主线) branch(分支) tag(标记) 用法详解和详细操作步骤(转)

    使用场景: 假如你的项目(这里指的是手机客户端项目)的某个版本(例如1.0版本)已经完成开发.测试并已经上线了,接下来接到新的需求,新需求的开发需要修改多个文件中的代码,当需求已经开始开发一段时间的时 ...

  3. SVN trunk(主线) branch(分支) tag(标记) 用法详解和详细操作步骤

    使用场景: 假如你的项目(这里指的是手机客户端项目)的某个版本(例如1.0版本)已经完成开发.测试并已经上线了,接下来接到新的需求,新需求的开发需要修改多个文件中的代码,当需求已经开始开发一段时间的时 ...

  4. CodeForces 474B E(Contest #1)

    题意: 给你一个数n,代表n段区间,接下来有n个数(a1,a2,...an)代表每段区间的长度,第一段区间为[1,a1],第二段区间为[a1+1,a1+a2],...第i段区间为[ai-1+1,ai- ...

  5. svn分支使用 SVN trunk(主线) branch(分支) tag(标记) 用法详解和详细操作步骤

    比较好的介绍了分支的创建和使用. 转:http://blog.csdn.net/vbirdbest/article/details/51122637

  6. CodeForces 474B Worms (水题,二分)

    题意:给定 n 堆数,然后有 m 个话询问,问你在哪一堆里. 析:这个题是一个二分题,但是有一个函数,可以代替写二分,lower_bound. 代码如下: #include<bits/stdc+ ...

  7. Codeforces 909 substr用法 思维合并线段目标最少 Py语句逆推DP vecrtor缩点删不同颜色点模拟 拓扑排序处理任务

    A str.substr(i,j) 从str[i]开始起取j个字符作为返回的字符串 /* Huyyt */ #include <bits/stdc++.h> using namespace ...

  8. Codeforces 474B. Worms

    It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mo ...

  9. WPF扩展标记

    标记扩展和 WPF XAML,标记扩展是 XAML 语言以及 XAML 服务的 .NET 实现的常规功能 XAML 处理器和标记扩展 XAML 分析器可将特性值解释为可转换成基元的文本字符串,或可通过 ...

随机推荐

  1. Nodejs in Visual Studio Code 06.新建Module

    1.开始 Node.js:https://nodejs.org 2.Moudle js编程中,由于大家可以直接在全局作用域中编写代码,使开发人员可以很容易的新建一个全局变量或这全局模块,这些全局变量或 ...

  2. C# RAS 非对称加密类 支持长字符串

    /// <summary> /// ikmb@163.com /// </summary> public class MyRAS { /// <summary> / ...

  3. 程序集引用异常 处理 app.config内控制runtime运行时应用的程序集版本指向 assemblyBinding结点 bindingRedirect

    异常: 解决方法: <?xml version="1.0" encoding="utf-8"?> <configuration> < ...

  4. ServletConfig

    ServletConfig Servlet配置 比如web程序中的某一个Servlet需要配置一些初始化信息,需要在web.xml中进行配置 <servlet> <servlet-n ...

  5. dubbo源码分析二:服务发布

    本文将深入分析dubbo的服务发布涉及到的流程及主要类的代码.首先,我们先从类的关系图来看一下dubbo发布服务涉及到的相关类. 1.类图 上图展示了部分服务发布过程中需要使用到的类和接口,其中: s ...

  6. OpenCV 编码样式指南

    OpenCV 编码样式指南   前言 本文档是对OpenCV中代码风格的简短说明,因为OpenCV的核心库(cv,cvaux)是用C和C++编写的,所以本文档仅对用C和C++代码的编写有效.   文件 ...

  7. 关于 Head First SQL 中文版

    我想谈谈 我对于Head  First  SQL  中文版的一些看法 事实上关于我翻译的这个Head  First  SQL 中文版..我自觉得:的确翻译得非常烂.. 和翻译Head  First  ...

  8. 从零单排c++ primer(17)

    (1)假设一个名字在派生类的作用域内无法正确解析,则编译器将继续在外层的基类作用域中寻找该名字的定义. (2)派生类的成员将隐藏同名的基类成员. (3)除了覆盖继承而来的虚函数之外,派生类最好不要重用 ...

  9. Android源代码分析之Framework的MediaPlayer

    在Android中MediaPlayer用来播放音频和视频文件,在这里分析下在Framework层中MediaPlayer是怎样调用的.MediaPlayer的代码位于:./frameworks/ba ...

  10. Java中如何分析一个案列---猫狗案例为例

    猫狗案例: 具体事务: 猫.狗 共性: 姓名.年龄.吃饭 分析:从具体到抽象 猫: 姓名.年龄--->成员变量 吃饭       ---> 成员方法 构造方法:无参.有参 狗: 姓名.年龄 ...