题目传送门

 /*
题意:问值为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的更多相关文章

  1. 贪心/二分查找 BestCoder Round #43 1002 pog loves szh II

    题目传送门 /* 贪心/二分查找:首先对ai%=p,然后sort,这样的话就有序能使用二分查找.贪心的思想是每次找到一个aj使得和为p-1(如果有的话) 当然有可能两个数和超过p,那么an的值最优,每 ...

  2. 二分查找 BestCoder Round #42 1002 Gunner II

    题目传送门 /* 题意:查询x的id,每次前排的树倒下 使用lower_bound ()查找高度,f[i]记录第一棵高度为x树的位置,查询后+1(因为有序) */ #include <cstdi ...

  3. ACM学习历程—HDU5592 ZYB's Premutation(逆序数 && 树状数组 && 二分)(BestCoder Round #65 1003)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5592 题目大意就是给了每个[1, i]区间逆序对的个数,要求复原原序列. 比赛的时候2B了一发. 首先 ...

  4. BestCoder Round #36

    HDU5198 Strange Class 问题描述 在Vivid的学校里,有一个奇怪的班级(SC).在SC里,这些学生的名字非常奇怪.他们的名字形式是这样的anbncn(a,b,c两两不相同.).例 ...

  5. 二分查找/暴力 Codeforces Round #166 (Div. 2) B. Prime Matrix

    题目传送门 /* 二分查找/暴力:先埃氏筛选预处理,然后暴力对于每一行每一列的不是素数的二分查找最近的素数,更新最小值 */ #include <cstdio> #include < ...

  6. BestCoder Round #36 [B] Gunner

    题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=5199 先对树的高度排序,然后对每次射击高度二分查找即可,打过之后数目变为0. #include< ...

  7. Bestcoder BestCoder Round #28 A Missing number(查找缺失的合法数字)

    Problem Description There is a permutation without two numbers in it, and now you know what numbers ...

  8. 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 ...

  9. jvascript 顺序查找和二分查找法

    第一种:顺序查找法 中心思想:和数组中的值逐个比对! /* * 参数说明: * array:传入数组 * findVal:传入需要查找的数 */ function Orderseach(array,f ...

随机推荐

  1. C语言socket send()数据缓存问题

    send()函数默认情况下会使用Nagle算法.Nagle算法通过将未确认的数据存入缓冲区直到积攒到一定数量一起发送的方法.来降低主机发送零碎小数据包的数目.所以假设send()函数发送数据过快的话, ...

  2. 赵雅智_SimpleCursorAdapter

    项目步骤 声明listView控件并获取显示的视图 获取显示的数据 设置显示的adapter 注冊点击事件 详细案例 实现效果: watermark/2/text/aHR0cDovL2Jsb2cuY3 ...

  3. PowerDesigner逆向工程,从SQL Server数据库生成Physical Model

    提前声明:这种方式貌似只能是Power Designer安装在数据库服务器的时候才可以,因为我按照成功的这个再去从本机逆向连接远程服务器的时候,一直提示:test failed......不讲了,尴尬 ...

  4. 闭包传参 余额计算 钩子hook 闭包中的this JavaScript 钩子

    闭包传参  余额计算    钩子hook 小程序 a=function(e){console.log(this)}() a=function(e){console.log(this)}() VM289 ...

  5. JDK and JRE File Structure JAVA_HOME HotSpot优化技术

    https://docs.oracle.com/javase/8/docs/technotes/tools/windows/jdkfiles.html Java Platform, Standard ...

  6. Java对对象的引用 不是 引用调用 而是按值引用 Java不存在引用调用

    call by reference Java call by value

  7. 从小姐姐博客那里看到的流光文字(CSS3 animate)

    对于流光文字,大家并不陌生,毕竟我们都经历过非主流的时代.你们卟懂绯紸流!色彩缤纷的QQ空间...... 还记得那些炫酷的签名档,或者那些炫酷的动态头像.不过大家对于流光文字的印象还是图片.那么在网页 ...

  8. 织梦dedecms中修改标题与简略标题长度的方法

    本文介绍了dedecms中修改标题与简略标题长度的方法,进入dedecms后台,系统——系统基本参数——其他选项——文档标题最大长度——在这修改为200或更大. 一.修改标题 进入dedecms后台, ...

  9. ssm使用velocity模板语言

    1.在pom.xml里添加velocity模板语言支持的依赖 <!-- velocity模板语言支持包 --> <dependency> <groupId>org. ...

  10. [推荐]Silverlight 2 开发者海报

    从Brad Abrams的Blog上看到了一张Silverlight 2开发者海报,非常酷,拿出来与大家分享. [JPG版本 5.8MB] [PNG版本 6.5MB] [TIF版本 19.9 MB] ...