主题链接:http://codeforces.com/contest/474/problem/B

#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstdio> using namespace std; template <class T>
inline bool rd(T &ret) {
char c; int sgn;
if(c=getchar(),c==EOF) return 0;
while(c!='-'&&(c<'0'||c>'9')) c=getchar();
sgn=(c=='-')?-1:1;
ret=(c=='-')?0:(c-'0');
while(c=getchar(),c>='0'&&c<='9') ret=ret*10+(c-'0');
ret*=sgn;
return 1;
}
template <class T>
inline void pt(T x) {
if (x <0) {
putchar('-');
x = -x;
}
if(x>9) pt(x/10);
putchar(x%10+'0');
} const int N = 100005;
int a[N], n; int main(){
while(rd(n)){
for(int i = 1; i <= n; i++)rd(a[i]);
for(int i = 2; i <= n; i++)a[i]+=a[i-1];
a[0] = -100;
a[n+1] = 10000000;
int que, u; rd(que);
while(que--){
rd(u);
int v = lower_bound(a+1, a+2+n, u) - a;
if(a[v] == u)
pt(v);
else
pt(v); putchar('\n');
}
}
return 0;
}

版权声明:本文博客原创文章,博客,未经同意,不得转载。

Codeforces 474B Worms 二分法(水的更多相关文章

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

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

  2. Codeforces 474B. Worms

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

  3. CodeForces 474B(标记用法)

    CodeForces 474B Time Limit:1000MS Memory Limit:262144KB   64bit IO Format:%I64d & %I64u Descript ...

  4. CodeForces.158A Next Round (水模拟)

    CodeForces.158A Next Round (水模拟) 题意分析 校赛水题的英文版,坑点就是要求为正数. 代码总览 #include <iostream> #include &l ...

  5. Codeforces Gym 100531G Grave 水题

    Problem G. Grave 题目连接: http://codeforces.com/gym/100531/attachments Description Gerard develops a Ha ...

  6. CodeForces 705A(训练水题)

    题目链接:http://codeforces.com/problemset/problem/705/A 从第三个输出中可看出规律, I hate that I love that I hate it ...

  7. CodeForces Gym 100685C Cinderella (水题)

    题意:给定 n 个杯子,里面有不同体积的水,然后问你要把所有的杯子的水的体积都一样,至少要倒少多少个杯子. 析:既然最后都一样,那么先求平均数然后再数一下,哪个杯子的开始的体积就大于平均数,这是一定要 ...

  8. CodeForces 534B Covered Path (水题)

    题意:给定两个速度,一个一初速度,一个末速度,然后给定 t 秒时间,还每秒速度最多变化多少,让你求最长距离. 析:其实这个题很水的,看一遍就知道怎么做了,很明显就是先从末速度开始算起,然后倒着推. 代 ...

  9. CodeForces 706C Hard problem (水DP)

    题意:对于给定的n个字符串,可以花费a[i]  将其倒序,问是否可以将其排成从大到小的字典序,且花费最小是多少. 析:很明显的水DP,如果不是水DP,我也不会做.... 这个就要二维,d[2][max ...

随机推荐

  1. mysql 监控 大批量的插入,删除,和修改

    监控大批量的插入,修改和删除: mysql> insert into aaa select * from aaa; mysql> SELECT trx_id, trx_state, trx ...

  2. Android 富文本框实现 RichEditText

    Android系统自带控件没有富文本框控件,如果想写一封带格式的邮件基本上不可能,EdtiText只有默认一种格式,显示不能滿足要求,!!正好项目需要研究了一下,开发了此控件,现将一些源代码开放一下, ...

  3. 改动项目APP名字后,在真机执行报错:The provisioning profile specified in your build settings (“haotian”) has an AppI

    错误提醒:The provisioning profile specified in your build settings ("haotian") has an AppID of ...

  4. What’s new in Spark 1.2.0

    What's new in Spark 1.2.0 1.2.0 was released on 12/18, 2014 在2014年5月30日公布了Spark 1.0 和9月11日公布了Spark1. ...

  5. 编译kernel:配置

    韦东山Linux视频第1期_裸板_UBoot_文件系统_驱动初步\第10课第2节 内核启动流程分析之配置.WMV 下面以DM9000的配置为例: 在一个编译好的内核代码里,寻找CONFIG_DM900 ...

  6. 12.5.3 UNIVERSAL:最终的祖先类:

    <pre name="code" class="html">12.5.3 UNIVERSAL:最终的祖先类: 你可以把 UNIVERSAL 看作最终 ...

  7. 【模式识别】Boosting

    Boosting简单介绍 分类中通常使用将多个弱分类器组合成强分类器进行分类的方法,统称为集成分类方法(Ensemble Method).比較简单的如在Boosting之前出现Bagging的方法,首 ...

  8. 如何把 excel 的数据导入到数据库里面去

    1. 把 excel 另存为 .csv 格式 2. 用 Notepad 打开 .csv 文件, 第一行就是全部的字段 3. 创建表结构 create table yu_rt_01 as select ...

  9. new对象数组时的内存布局

    #include <iostream> #include <limits> using namespace std; #define SAFE_DELETE(x) \ { \ ...

  10. Javascript 进阶 封装

    js中处处是对象,面向对象的第一步当然就是封装了,由于Js中没有类的概念,所以封装起来也比较麻烦,下面介绍两种js的封装. 1.使用约定优先的原则,将所有的私有变量以_开头 <script ty ...