Educational Codeforces Round 2 B.Queries about less or equal elements(排序&&二分)
2016-01-16 22:07
477 查看
Educational Codeforces Round 2B:http://codeforces.com/contest/600/problem/B
B. Queries about less or equal elements
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
You are given two arrays of integers a and b.
For each element of the second array bj you
should find the number of elements in arraya that are less than or equal to the value bj.
Input
The first line contains two integers n, m (1 ≤ n, m ≤ 2·105)
— the sizes of arrays a and b.
The second line contains n integers — the elements of array a ( - 109 ≤ ai ≤ 109).
The third line contains m integers — the elements of array b ( - 109 ≤ bj ≤ 109).
Output
Print m integers, separated by spaces: the j-th
of which is equal to the number of such elements in array a that are less than or equal to the value bj.
Sample test(s)
input
output
input
output
题目大意:对b数组中的每一个数b[j]找到a数组中小于等于b[j]的数的个数
大致思路:对a数组排序,用二分找第一个大于等于b[j]的数,下标就是所求个数
这么简单的题,一个月前第一次看竟然没有反应过来
B. Queries about less or equal elements
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
You are given two arrays of integers a and b.
For each element of the second array bj you
should find the number of elements in arraya that are less than or equal to the value bj.
Input
The first line contains two integers n, m (1 ≤ n, m ≤ 2·105)
— the sizes of arrays a and b.
The second line contains n integers — the elements of array a ( - 109 ≤ ai ≤ 109).
The third line contains m integers — the elements of array b ( - 109 ≤ bj ≤ 109).
Output
Print m integers, separated by spaces: the j-th
of which is equal to the number of such elements in array a that are less than or equal to the value bj.
Sample test(s)
input
5 4 1 3 5 7 9 6 4 2 8
output
3 2 1 4
input
5 5 1 2 1 2 5 3 1 4 1 5
output
4 2 4 2 5
题目大意:对b数组中的每一个数b[j]找到a数组中小于等于b[j]的数的个数
大致思路:对a数组排序,用二分找第一个大于等于b[j]的数,下标就是所求个数
这么简单的题,一个月前第一次看竟然没有反应过来
#include <cstdio> #include <algorithm> using namespace std; int a[200005],n,m,i,b; int main() { while(2==scanf("%d%d",&n,&m)) { for(i=0;i<n;++i) scanf("%d",a+i); sort(a,a+n); a[n++]=0x3f3f3f3f; scanf("%d",&b); printf("%d",upper_bound(a,a+n,b)-a); while(--m) { scanf("%d",&b); printf(" %d",upper_bound(a,a+n,b)-a); } printf("\n"); } return 0; }
相关文章推荐
- UESTC--1271--Search gold(贪心)
- UESTC--1271--Search gold(贪心)
- UI学习第06天
- getRequestDispatcher()与sendRedirect()的区别
- 关于UIWindow的一点儿思考
- iOS - UICollectionView学习
- UITextFielddelegate委托方法注释
- UESTC Memory 1262 (打表&暴力模拟)
- UESTC第七届ACM趣味程序设计竞赛第四场(正式赛)
- 【SSH网上商城】Incorrect datetime value: '' for column 'pdate' at row 1
- UESTC--1272--Final Pan's prime numbers(水题)
- 内核发送uevent的API,用户空间解析uevent
- UESTC--1272--Final Pan's prime numbers(水题)
- 批处理文件:实现将写好的Android Uiautomator工程打包成jar包放到手机中执行
- UI小结.(一)
- UESTC--1269--ZhangYu Speech(模拟)
- UESTC--1269--ZhangYu Speech(模拟)
- UESTC--1265--宝贵资源(简单数学)
- UESTC--1265--宝贵资源(简单数学)
- UESTC--1264