Codeforces 474B Worms 二分法(水
主题链接: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 二分法(水的更多相关文章
- CodeForces 474B Worms (水题,二分)
题意:给定 n 堆数,然后有 m 个话询问,问你在哪一堆里. 析:这个题是一个二分题,但是有一个函数,可以代替写二分,lower_bound. 代码如下: #include<bits/stdc+ ...
- Codeforces 474B. Worms
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mo ...
- CodeForces 474B(标记用法)
CodeForces 474B Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Descript ...
- CodeForces.158A Next Round (水模拟)
CodeForces.158A Next Round (水模拟) 题意分析 校赛水题的英文版,坑点就是要求为正数. 代码总览 #include <iostream> #include &l ...
- Codeforces Gym 100531G Grave 水题
Problem G. Grave 题目连接: http://codeforces.com/gym/100531/attachments Description Gerard develops a Ha ...
- CodeForces 705A(训练水题)
题目链接:http://codeforces.com/problemset/problem/705/A 从第三个输出中可看出规律, I hate that I love that I hate it ...
- CodeForces Gym 100685C Cinderella (水题)
题意:给定 n 个杯子,里面有不同体积的水,然后问你要把所有的杯子的水的体积都一样,至少要倒少多少个杯子. 析:既然最后都一样,那么先求平均数然后再数一下,哪个杯子的开始的体积就大于平均数,这是一定要 ...
- CodeForces 534B Covered Path (水题)
题意:给定两个速度,一个一初速度,一个末速度,然后给定 t 秒时间,还每秒速度最多变化多少,让你求最长距离. 析:其实这个题很水的,看一遍就知道怎么做了,很明显就是先从末速度开始算起,然后倒着推. 代 ...
- CodeForces 706C Hard problem (水DP)
题意:对于给定的n个字符串,可以花费a[i] 将其倒序,问是否可以将其排成从大到小的字典序,且花费最小是多少. 析:很明显的水DP,如果不是水DP,我也不会做.... 这个就要二维,d[2][max ...
随机推荐
- 严重: Servlet.service() for servlet jsp threw exception java.lang.IllegalStateException: getOutputStream() has already been called
错误: 严重: Servlet.service() for servlet jsp threw exception java.lang.IllegalStateException: getOutput ...
- scrapy新浪天气
一.实验说明 1. 环境登录 无需密码自动登录,系统用户名shiyanlou 2. 环境介绍 本实验环境采用带桌面的Ubuntu Linux环境,实验中会用到桌面上的程序: LX终端(LXTermin ...
- 高级特性(8)- JavaBean构件
8.1 为何使用Bean8.2 编写Bean的过程8.3 使用Bean构造应用程序 8.3.1 将Bean打包成JAR文件 8.3.2 在开发环境中组合Bean8.4 Bean属性与事件的命名模式8. ...
- opencv实现连通域
在本文中使用图像连通域统计使用opencv中的cvFloodFill方法,可是在cvFloodFill方法中CvConnectedComp參数无法返回详细点坐标位置信息,找了些资料.给CvSeq分配空 ...
- Android Drawable 与 LayerList综合汇总
先看需求.要求这样的效果 上代码 <?xml version="1.0" encoding="utf-8"? > <layer-list xm ...
- perl use utf8
utf8 Perl编译 来启用/禁用 UTF-8(or UTF-EBCDIC) 在源代码里 简洁: use utf8; no utf8; # Convert the internal represen ...
- FastReport 数据过滤
FastReport 数据过滤 在DataBind 的 OnBeforePrint 设置条件 例:显示 大于0 的数据 procedure MasterData1OnBeforePrint(Sen ...
- 一起C语言中程序时序问题的排查过程
[文章摘要] 对于由多个模块协同工作的软件来说,程序处理的时序是很重要的.当消息处理的顺序出现混乱时,程序就会出现异常. 本文基于作者的实际项目经验.对软件模块之间的时序问题进行了具体的分析,为相关软 ...
- URAL 1180. Stone Game (博弈 + 规律)
1180. Stone Game Time limit: 1.0 second Memory limit: 64 MB Two Nikifors play a funny game. There is ...
- Writing a Windows Shell Extension(marco cantu的博客)
Writing a Windows Shell Extension This is a technical article covering the content of my last week s ...