Letters CodeForces - 978C(水题,low_bound()函数使用)
水题,记录一下low_bound(*begin,*end,num),其中low-bound是指以num为下界,寻找第一个比num大或相等的元素的指针,通过减去*begin指针我们可以获得相应的下标。
upper_bound( first, last, & val)算法返回一个非递减序列[first, last)中第一个 大于 val的地址。
lower_bound( first, last, & val)算法返回一个非递减序列[first, last)中第一个 大于等于 值val的地址。
区别好像就是lower_bound会返回等于的值,但是upper_bound是严格大于。
AC代码:
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long ll;
const int maxn=1e6+5;
ll n,m,a[maxn],b[maxn],sum[maxn];
int main(){ios::sync_with_stdio(false);cin>>n>>m;for(int i=1;i<=n;i++){cin>>a[i];sum[i]=sum[i-1]+a[i];}for(int i=1;i<=m;i++)cin>>b[i];for(int i=1;i<=m;i++){//ll index=upper_bound(sum,sum+n+1,b[i])-sum;ll index=lower_bound(sum,sum+n+1,b[i])-sum;cout<<index<<" "<<b[i]-sum[index-1]<<endl;}
}
Letters CodeForces - 978C(水题,low_bound()函数使用)相关推荐
- codeforces 1041a(水题)
http://codeforces.com/problemset/problem/1041/A(题目链接) There was an electronic store heist last night ...
- 闲来无事刷水题、简单博弈论专题、sg函数、洛谷
记 今天闲来无事,不想刷codeforces了,到洛谷提高组训练营找几道水题刷着玩玩(虽然自己早已过了打OI的年纪)- 简单博弈论专题 P1199 三国游戏 这么考虑,由于电脑总是不能让我搭配出当前能 ...
- Codeforces 864 A Fair Game 水题
题目链接: http://codeforces.com/problemset/problem/864/A 题目描述: 看不是是不是一串数中只有两种数且这两种数字的数量是相同的 解题思路: 水题, 水过 ...
- Codeforces Round #355 (Div. 2) B. Vanya and Food Processor 水题
B. Vanya and Food Processor 题目连接: http://www.codeforces.com/contest/677/problem/B Description Vanya ...
- Educational Codeforces Round 7 B. The Time 水题
B. The Time 题目连接: http://www.codeforces.com/contest/622/problem/B Description You are given the curr ...
- 【CodeForces - 289C】Polo the Penguin and Strings (水题,字符串,思维构造,有坑)
题干: Little penguin Polo adores strings. But most of all he adores strings of length n. One day he wa ...
- 【CodeForces - 1A】Theatre Square(水题,几何)(CODEFORCES,梦的开始)
题干: Theatre Square in the capital city of Berland has a rectangular shape with the size n × m meters ...
- Codeforces Round #343 (Div. 2) A. Far Relative’s Birthday Cake 水题
A. Far Relative's Birthday Cake 题目连接: http://www.codeforces.com/contest/629/problem/A Description Do ...
- Codeforces数据结构(水题)小结
最近在使用codeblock,所以就先刷一些水题上上手 使用codeblock遇到的问题 1.无法进行编译-------从setting中的编译器设置中配置编译器 2.建立cpp后无法调试------ ...
最新文章
- JVM调优:基本垃圾回收算法
- crontab工具介绍
- 【C 语言】二级指针作为输入 ( 二维数组 | 二维数组内存大小计算 | 指针跳转步长问题 )
- LIVE555再学习 -- testRTSPClient 源码分析
- IntelliJ IDEA for Mac 修改项目模块的名称
- 还是想继续写代码,不想这么快就去养猪~
- 计算领域的致敬与前行
- discuz mysql 类_discuz7 phpMysql操作类
- 【TensorFlow】TensorFlow从浅入深系列之八 -- 教你学会变量管理
- S2D_基于深度学习的视觉稠密建图和定位_相关文章
- Julia: [1 +j] ==[1 + j] ?
- 圆面积公式积分法推导
- 【nodejs】mocha+chai+nyc基础
- 【SpringBoot】之自定义 Filter 过滤器
- 路由器交换与配置综合实验(二)外网
- Linux驱动——mmc sd card 块设备读写流程(十三)
- 网狐棋牌为服务器大厅加载游戏注意事项
- 【FPGA教程案例96】控制案例1——基于FPGA的自适应PID控制器verilog实现
- 张国宝:东北地区经济社会发展加快
- 这份“插件英雄榜Top40”才是Chrome的正确打开方式!(Github7000+ Stars)