题目传送门

 /*
题意:问值为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. Python 003- 小知识汇总(更新中)

    #查询key是否存在,可以在使用未知的字典的时候使用 #-*- coding:utf-8 -*- D={'a':1,'c':3,'b':2} for key in sorted(D): print(k ...

  2. CentOS笔记-其他杂记

    1.忘记密码时,可以用single模式来修改密码,为了安全,可以禁用single模式,参考网址如下 Centos服务器禁止单用户模式(single)来增强系统安全 2.远程登录:ssh root@xx ...

  3. 4.改变eclipse选中文字颜色

    window-preferences-general-editors-text editors-annotations-occurrences 和 window-preferences-general ...

  4. quilt

    1 什么是quilt quilt是一个patch管理工具,特别适合于对多个patch进行管理. quilt是基于gnu patch和diff的. 2 使用quilt创建一个patch 第一步,quil ...

  5. Mac 下如何安装pip 和xlwt

    sudo easy_install pip pip install xlwt sudo pip install xlwt sudo pip install requests

  6. ivy

    ivy https://ant.apache.org/ivy/ Apache Ivy™ is a popular dependency manager focusing on flexibility ...

  7. hdoj 1875 畅通project再续【最小生成树 kruskal &amp;&amp; prim】

    畅通project再续 Problem Description 相信大家都听说一个"百岛湖"的地方吧,百岛湖的居民生活在不同的小岛中,当他们想去其它的小岛时都要通过划小船来实现. ...

  8. (29)java web的hibernate使用-crud的dao

    1, 做个简单的util public class HibernateUtils { private static SessionFactory sf; static { //加载主要的配置文件 sf ...

  9. Java 字符串比较小知识

    使用 String.compareTo 方法: compareTo() 的返回值是int, 它是先比较对应字符的大小(ASCII码顺序). 1.如果字符串相等,返回值0. 2.如果第一个字符和参数的第 ...

  10. android 一个TextView设置多种颜色

    时候一个文本框为了强调内容需要显示不同颜色,用以下代码可以轻松实现 方法一:(适用于颜色变化多的情况)   //为文本框设置多种颜色 textView=(TextView)findViewById(R ...