Codeforces Educational Codeforces Round 2 B. Queries about less or equal elements
2015-11-29 21:02
417 查看
题目链接
题意:
a
和 b[m],对于每个b[i], 求a
中有几个元素 <= b[i]
思路:
看到<=,第一反应想到lower_bound,但是这是查询第一个小于等于的元素的位置,但是有多个元素等于b[i],就会出错
用upper_bound就不会啦~
代码如下:
题意:
a
和 b[m],对于每个b[i], 求a
中有几个元素 <= b[i]
思路:
看到<=,第一反应想到lower_bound,但是这是查询第一个小于等于的元素的位置,但是有多个元素等于b[i],就会出错
用upper_bound就不会啦~
代码如下:
#include<cstdio> #include<cstring> #include<algorithm> using namespace std; const int N = 2E5 + 10; int n, m; int a , b ; int main() { while(~scanf("%d%d", &n, &m)) { for(int i = 0; i < n; i++) scanf("%d", &a[i]); sort(a, a + n); for(int j = 0; j < m; ++j) scanf("%d", &b[j]); for(int i = 0; i < m; i++) { if(i == m) printf("%d\n", upper_bound(a ,a + n, b[i]) - a); else printf("%d ",upper_bound(a, a + n, b[i]) - a); } } return 0; }
相关文章推荐
- vidioc_querycap浅析
- 爬爬爬之路:UI(十二) 单例 UITabBarController 高级Block的应用
- Java基础---图形用户界面GUI(一)
- Educational Codeforces Round 2 B. Queries about less or equal elements 水题
- Android UICC 好文关键字备忘
- html/jsp 利用juicer模版添加页面标签内容
- 【Educational Codeforces Round 2B】【map or 二分查找】Queries about less or equal elements b[]中的每个数比a[]中多少数大
- 新手学EasyUI(八)----SubGrid三级嵌套
- UI控件的一些问题与解决方法
- UGUI摇杆
- Ubuntu10.04上编译Android源码(Build Android source in Ubuntu10.04 Platform)
- UI推荐
- UI_layoutSubView(判断横竖屏方法)
- SequenceInputStream
- UINavigationController
- UIWindow简单介绍
- 【iOS】UITableView 动态确定cell的高度
- Win7 64位 VS2013环境编译Squirrel 3.0.7
- UIMenuController的基本用法
- iOS之微博UI实例--拟物化设计(成功了90%)