Gunner II



Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)

Total Submission(s): 1244    Accepted Submission(s): 486



Problem Description

Long long ago, there was a gunner whose name is Jack. He likes to go hunting very much. One day he go to the grove. There are n birds and n trees. The i-th bird stands on the top of the i-th tree. The trees stand in straight line from left to the right. Every
tree has its height. Jack stands on the left side of the left most tree. When Jack shots a bullet in height H to the right, the nearest bird which stands in the tree with height H will falls.

Jack will shot many times, he wants to know which bird will fall during each shot.

 

Input

There are multiple test cases (about 5), every case gives n, m in the first line, n indicates there are n trees and n birds, m means Jack will shot m times. 

In the second line, there are n numbers h[1],h[2],h[3],…,h[n] which describes the height of the trees.

In the third line, there are m numbers q[1],q[2],q[3],…,q[m] which describes the height of the Jack’s shots.

Please process to the end of file.

[Technical Specification]

All input items are integers.

1<=n,m<=100000(10^5)

1<=h[i],q[i]<=1000000000(10^9)

 

Output

For each q[i], output an integer in a single line indicates the id of bird Jack shots down. If Jack can’t shot any bird, just output -1.

The id starts from 1.

 

Sample Input

5 5

1 2 3 4 1

1 3 1 4 2

 

Sample Output

1

3

5

4

2

//这题主要思路就是利用一个结构体将高度与序号记录下来
//再利用一个数组将高度排序而且标记高度出现的顺序 #include <stdio.h>
#include <algorithm>
using namespace std;
int flag[100010],h[100010]; struct bird
{
int n,num;
}p[100010]; bool cmp(const bird &a,const bird &b)
{
return a.n!=b.n? a.n<b.n:a.num<b.num;
} int main()
{
int n,m;
while(~scanf("%d%d",&n,&m))
{
for(int i=0;i<n;i++ )
{
scanf("%d",&p[i].n);
p[i].num=i+1;
}
sort(p,p+n,cmp);
for(int i=0;i<n;i++)
{
flag[i]=i; //此时的flag数组是标记高度第一次出现的位置
h[i]=p[i].n;
}
while(m--)
{
int x;
scanf("%d",&x);
int q=lower_bound(h,h+n,x)-h; //查询到的也是第一次出现的次数
if(h[flag[q]]!=x)
{
printf("-1\n");
continue;
}
else
printf("%d\n",p[flag[q]].num);
flag[q]++; //因为查询过一次了 所以递增到下一个高度
}
}
return 0;
}

HDU5233的更多相关文章

  1. hdu5233 Gunner II

    Problem Description Long long ago, there was a gunner whose name is Jack. He likes to go hunting ver ...

  2. Beatcoder#39+#41+#42

    HDU5211 思路: 倒着更新每个数的约数,更新完要把自己加上,以及1的情况? //#include <bits/stdc++.h> #include<iostream> # ...

随机推荐

  1. 具体图解 Flume介绍、安装配置

    写在前面一: 本文总结"Hadoop生态系统"中的当中一员--Apache Flume 写在前面二: 所用软件说明: 一.什么是Apache Flume 官网:Flume is a ...

  2. Android新手入门2016(8)--ListView之ArrayAdapter

    本文来自肥宝传说之路,引用必须注明出处! ListView是Android中经常使用的控件. 什么是列表视图,让我们先看看图: watermark/2/text/aHR0cDovL2Jsb2cuY3N ...

  3. zzulioj--1637--Happy Thanksgiving Day - WoW yjj!(水)

    1637: Happy Thanksgiving Day - WoW yjj! Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 104  Solved: ...

  4. 均匀分布(uniform distribution)期望的最大似然估计(maximum likelihood estimation)

    maximum estimator method more known as MLE of a uniform distribution [0,θ] 区间上的均匀分布为例,独立同分布地采样样本 x1, ...

  5. System.setProperty 与 System.getProperty

    转自:https://www.cnblogs.com/woftlcj/p/8404451.html System可以有对标准输入,标准输出,错误输出流:对外部定义的属性和环境变量的访问:加载文件和库的 ...

  6. Hessian Servlet实例

    Servlet实例 业务场景 在下面的例子中我会发布一个简单的输出字符串的方法,然后在客户端调用并输出结果. 服务器端 环境搭建 在服务端,我们需要引入hessian和servlet的包.编写服务.配 ...

  7. Python—使用xm.dom解析xml文件

    什么是DOM? 文件对象模型(Document Object Model,简称DOM),是W3C组织推荐的处理可扩展置标语言的标准编程接口. 一个 DOM 的解析器在解析一个 XML 文档时,一次性读 ...

  8. ubuntu DNS 出错,用以下命令可以解决

    具体的错误为:DNS_PROBE_FINISHED_BAD_CONFIG 命令为: sudo rm /etc/resolv.conf sudo ln -s ../run/resolvconf/reso ...

  9. Chosen:Select 选择框的华丽变身

    HTML Form 表单里的各种组件,例如文本输入框,textarea,按钮等,都可以通过CSS或其它技术进行美化,让它们看起来很漂亮了,唯独下拉列表选项框(select box),不管你怎么做,它摆 ...

  10. Repeater控件使用小结持续更新

    Repeater嵌套Repeater绑定数据 前台代码 <!--注意层级关系不要写错了--> <asp:Repeater ID="rpGroup" runat=& ...