B - Worms (未解决
https://vjudge.net/problem/CodeForces-474B/origin
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 ≤ 103, a1 + 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.
Examples
5
2 7 3 4 9
3
1 25 11
1
5
3
Note
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.
判断该标号的物品在哪一段
OT(附未通过代码 以便补题):
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <cstring> using namespace std; int a[100005] = {0};
int main()
{
int n = 0;
cin >> n;
int sum = 0 , add = 0;
for(int i = 0;i<n;i++)
{
cin >> add;
sum += add;
a[i] = sum;
}
int m = 0;
int test = 0;
cin >> m;
for(int i = 0;i<m;i++)
{
cin >> test;
int p = n/2;
if(test <= a[0])
{
cout << 1 << endl;
continue;
}
while(1)
if(test > a[p])
{
p = (n+p)/2;
if(test > a[p-1] && test <= a[p])
break;
if(test > a[p] && test <= a[p+1])
{
p+=1;
break;
}
}
else
{
p = p/2;
if(test > a[p-1] && test <= a[p])
break;
if(test > a[p] && test <= a[p+1])
{
p+=1;
break;
}
}
cout << p+1 << endl;
}
return 0;
}
B - Worms
B - Worms (未解决的更多相关文章
- C/C++编译和链接过程详解 (重定向表,导出符号表,未解决符号表)
详解link 有 些人写C/C++(以下假定为C++)程序,对unresolved external link或者duplicated external simbol的错误信息不知所措(因为这样的错 ...
- 直接请求json文件爬取天眼查企业信息(未解决验证码问题)——python3实现
几个月前...省略一堆剧情...直接请求json文件爬取企业信息未成功,在知乎提问后,得到解决,有大佬说带上全部headers和cookie是可以的,我就又去试了下,果然可以(之前自己试的时候不行,没 ...
- 记一次未解决的异常:java.lang.NoClassDefFoundError: net/sf/json/JSONObject
原因:Jetty会导致这个问题,Tomcat可以正常启动 一.异常产生现象 使用json-lib转换实体类/字符串,跑单元测试没问题,但是启动jetty后调用JSONArray.fromObjec ...
- Ajax返回中文乱码问题(未解决)
(未解决) 暂时使用办法:改用返回Map<String,String>形式的返回值,在ajax中获取json形式的数据.
- openerp学习笔记 计算字段、关联字段(7.0中非计算字段、关联字段只读时无法修改保存的问题暂未解决)
计算字段.关联字段,对象修改时自动变更保存(当 store=True 时),当 store=False 时,默认不支持过滤和分组7.0中非计算字段.关联字段只读时无法修改保存的问题暂未解决 示例代码: ...
- oracle,wamp,FZ突然出现问题,求解决方案(未解决,最终系统还原)
-----背景------- 系统:win7 64位oracle 11g(11.1)每天都用oracle.用toad for oracle .电脑固定IP.未更改任何配置信息.用了几个月,突然出现了 ...
- (转载) C/C++编译和链接过程详解 (重定向表,导出符号表,未解决符号表)
转载http://blog.csdn.net/neo_ustc/article/details/9024839 有 些人写C/C++(以下假定为C++)程序,对unresolved external ...
- tomcat中显示本地图片①(未解决)
<本模块文仅作为学习过程中的自我总结,有需要可参看,欢迎指导与提出建议,很多地方可能断章取义,理解不到位,虚心求学.谢谢!> 资料查阅原因:2018/7/10(做项目中显示详情页面,从数据 ...
- JIRA状态为任务结束,但是解决结果为未解决相关配置
1.JIRA状态为任务结束,但是解决结果为未解决,如下图所示: 2.在工作流->界面->结果处理中进行解决结果的配置(首先确保界面配置中有“解决结果”字段). 3.点击“结果处理”,进行结 ...
- [未解决]Exception in thread "main" java.lang.IllegalArgumentException: offset (0) + length (8) exceed the capacity of the array: 6
调用这个方法 是报错,未解决 binfo.setTradeAmount(Double.parseDouble(new String(result.getValue(Bytes.toBytes(fami ...
随机推荐
- # Mit 6.824 Raft实验 2A 2B
Mit 6.824 Raft实验 2A 2B Author: Minghao Zhou 这个项目写了好久,从一点也看不懂开始,到最后debug就和回家一样自然,成就感还是很足的哈哈.看大佬的架构和代码 ...
- IntelliJ IDEA 中,项目文件右键菜单没有svn选项解决办法
问题描述 欲在IntelliJ IDEA中提交文件至SVN,但是在项目文件上点击右键时,发现右键菜单中没有Subversion的选项,正常情况下是要有的,如下图所示: 图0 解决办法 点击菜单:VCS ...
- 布局控件:Grid和StackPanel
布局控件:Grid和StackPanel 本文同时为b站WPF课程的笔记,相关示例代码 一个窗口顶上的部分叫做非客户区,下面的部分叫做客户区域.非客户区域主要就是一个Title和三个窗口样式按钮.我们 ...
- AI大模型应用开发入门-LangChain开发聊天机器人ChatBot
在大模型应用开发中,状态管理 和 对话追踪 是不可忽视的重要能力,尤其在需要保存上下文.重放对话或进行异步处理时尤为关键. 今天我们来演示如何用 LangChain + OpenAI 的 GPT 模型 ...
- Grafana监控指标、日志与链路追踪数据采集到GreptimeDB的完整实践指南
以下是将Grafana监控指标.日志与链路追踪数据采集到GreptimeDB的完整实践指南,涵盖部署.运维.安全及扩展的全流程: 一.整体架构 图表 二.数据采集配置 1. 指标采集(Promethe ...
- STM32深度学习实战
STM32深度学习实战 1. 前言 本文主要记录基于 tensorflow 的简单模型在 stm32 上运行测试的调试记录,开发人员应对深度学习基础理论和 tensorflow 框架基础操作有一定 ...
- DTALK直播预约 | 12月8日开播:后疫情时代,制造企业如何实现数字化转型?
我国制造业拥有31个大类.179个中类和609个小类,是全球产业门类最齐全.产业体系最完整的制造业.二十大报告中强调:"坚持把发展经济的着力点放在实体经济上""推动制造业 ...
- 如何在FastAPI中玩转GitHub认证,让用户一键登录?
title: 如何在FastAPI中玩转GitHub认证,让用户一键登录? date: 2025/06/22 09:11:47 updated: 2025/06/22 09:11:47 author: ...
- STM32学会要花费多长时间?一个从机械转行老程序员的血泪史
看到这个问题,我不禁想起了6年前那个拿着机械毕业证却被分配到电子部门的懵逼青年--没错,就是我. 当时坐在工位上,面对着桌上那块STM32F103的开发板,内心是崩溃的.我特么学了四年机械,研究生又搞 ...
- Selenium Grid的原理,配置和WEB UI分布式测试
selenium grid 用于webui automation的分布式测试, 一般常规情况下,测试不建议用多线程,多线程会有很多问题,比如并发,锁机制等,什么时候线程该动什么时候停,考虑并发协同机 ...