二分查找 BestCoder Round #36 ($) Gunner
/*
题意:问值为x的个数有几个,第二次查询就是0
lower/upper_bound ()函数的使用,map也可过,hash方法不会
*/
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <queue>
using namespace std; const int MAXN = 1e6 + ;
const int INF = 0x3f3f3f3f;
int a[MAXN], b[MAXN];
int used[MAXN];
int n, m; inline int read(void)
{
int x = , f = ; char ch = getchar ();
while (ch < '' || ch > '') {if (ch == '-') f = -; ch = getchar ();}
while (ch >= '' && ch <= '') {x = x * + ch - ''; ch = getchar ();}
return f * x;
} int main(void) //HDOJ 5199 Gunner
{
//freopen ("B.in", "r", stdin); while (scanf ("%d%d", &n, &m) == )
{
memset (used, , sizeof (used));
for (int i=; i<=n; ++i) a[i] = read ();
for (int i=; i<=m; ++i) b[i] = read (); sort (a+, a++n);
for (int i=; i<=m; ++i)
{
int x = upper_bound (a+, a++n, b[i]) - a;
int y = lower_bound (a+, a++n, b[i]) - a;
if (used[x])
{
puts (""); continue;
}
used[x] = ;
printf ("%d\n", x - y);
}
} return ;
}
#include <cstdio>
#include <iostream>
#include <cstring>
#include <map>
using namespace std; const int MAXN = 1e6 + ;
const int INF = 0x3f3f3f3f; inline int read(void)
{
int x = , f = ; char ch = getchar ();
while (ch < '' || ch > '') {if (ch == '-') f = -; ch = getchar ();}
while (ch >= '' && ch <= '') {x = x * + ch - ''; ch = getchar ();}
return f * x;
}
int main(void)
{
//freopen ("B.in", "r", stdin); int n, m;
while (scanf ("%d%d", &n, &m) == )
{
map<int, int> ma; int x;
while (n--)
{
x = read (); ma[x]++;
}
map<int, int>::iterator it;
while (m--)
{
x = read ();
it = ma.find (x);
if (it == ma.end ())
puts ("");
else
{
printf ("%d\n", it->second);
it->second = ;
}
}
} return ;
}
map
二分查找 BestCoder Round #36 ($) Gunner的更多相关文章
- 贪心/二分查找 BestCoder Round #43 1002 pog loves szh II
题目传送门 /* 贪心/二分查找:首先对ai%=p,然后sort,这样的话就有序能使用二分查找.贪心的思想是每次找到一个aj使得和为p-1(如果有的话) 当然有可能两个数和超过p,那么an的值最优,每 ...
- 二分查找 BestCoder Round #42 1002 Gunner II
题目传送门 /* 题意:查询x的id,每次前排的树倒下 使用lower_bound ()查找高度,f[i]记录第一棵高度为x树的位置,查询后+1(因为有序) */ #include <cstdi ...
- ACM学习历程—HDU5592 ZYB's Premutation(逆序数 && 树状数组 && 二分)(BestCoder Round #65 1003)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5592 题目大意就是给了每个[1, i]区间逆序对的个数,要求复原原序列. 比赛的时候2B了一发. 首先 ...
- BestCoder Round #36
HDU5198 Strange Class 问题描述 在Vivid的学校里,有一个奇怪的班级(SC).在SC里,这些学生的名字非常奇怪.他们的名字形式是这样的anbncn(a,b,c两两不相同.).例 ...
- 二分查找/暴力 Codeforces Round #166 (Div. 2) B. Prime Matrix
题目传送门 /* 二分查找/暴力:先埃氏筛选预处理,然后暴力对于每一行每一列的不是素数的二分查找最近的素数,更新最小值 */ #include <cstdio> #include < ...
- BestCoder Round #36 [B] Gunner
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=5199 先对树的高度排序,然后对每次射击高度二分查找即可,打过之后数目变为0. #include< ...
- Bestcoder BestCoder Round #28 A Missing number(查找缺失的合法数字)
Problem Description There is a permutation without two numbers in it, and now you know what numbers ...
- Codeforces Round #768 (Div. 2) D. Range and Partition // 思维 + 贪心 + 二分查找
The link to problem:Problem - D - Codeforces D. Range and Partition time limit per test: 2 second ...
- jvascript 顺序查找和二分查找法
第一种:顺序查找法 中心思想:和数组中的值逐个比对! /* * 参数说明: * array:传入数组 * findVal:传入需要查找的数 */ function Orderseach(array,f ...
随机推荐
- 二分法和牛顿迭代实现开根号函数:OC的实现
最近有人贴出BAT的面试题,题目链接. 就是实现系统的开根号的操作,并且要求一定的误差,其实这类题就是两种方法,二分法和牛顿迭代,现在用OC的方法实现如下: 第一:二分法实现 -(double)sqr ...
- Linux 及 CentOS系统安装
VMware与Centos系统安装 今日任务 .Linux发行版的选择 .vmware创建一个虚拟机(centos) .安装配置centos7 .xshell配置连接虚拟机(centos) 选择性 ...
- querying rpm database
Call dbMatch on a transaction set to create a match iterator. As with the C API, a match iterator al ...
- Ehcache CacheManager
CacheManager是Ehcache框架的核心类和入口,它负责管理一个或多个Cache对象.要使用Ehcache框架,必须要先创建 CacheManager 对象.现在我们学习下,如何创建 Cac ...
- Deep Learning 33:读论文“Densely Connected Convolutional Networks”-------DenseNet 简单理解
一.读前说明 1.论文"Densely Connected Convolutional Networks"是现在为止效果最好的CNN架构,比Resnet还好,有必要学习一下它为什么 ...
- 关于android的DB操作
package com.metoo.girls; import android.content.ContentValues; import android.content.Context; impor ...
- HDU3709 Balanced Number —— 数位DP
题目链接:https://vjudge.net/problem/HDU-3709 Balanced Number Time Limit: 10000/5000 MS (Java/Others) ...
- 织梦DEDE多选项筛选_联动筛选功能的实现_二次开发
织梦默认的列表页没有筛选功能,但有时候我们做产品列表页的时候,产品的字段比较多,很多人都需要用到筛选功能,这样可以让用户更方便的找到自己所需要的东西,实现这个联动筛选功能需要对织梦进行二次开发,下面就 ...
- 倒排列表求交集算法 包括baeza yates的交集算法
#ifndef __INTERSECT_HPP__ #define __INTERSECT_HPP__ #include "probe.hpp" namespace themas ...
- skynet源码阅读<3>--网关分析
继上一篇介绍了skynet的网络部分之后,这一篇以网关gate.lua为例,简单分析下其串接和处理流程. 在官方给出的范例中,是以examples/main.lua作为启动脚本的,在此过程中会创建wa ...