HDU5233
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的更多相关文章
- hdu5233 Gunner II
Problem Description Long long ago, there was a gunner whose name is Jack. He likes to go hunting ver ...
- Beatcoder#39+#41+#42
HDU5211 思路: 倒着更新每个数的约数,更新完要把自己加上,以及1的情况? //#include <bits/stdc++.h> #include<iostream> # ...
随机推荐
- python2.7编码与解码
常见的编码 ASCII: 美国人发明的,只编码英文字母和符号,1个字节. GB2312: 中国人发明的,增加了中文汉字和符号,2个字节. Unicode: 为了把所有语言都统一到一套编码里,一般是2个 ...
- Spring-SpringJdbcTemlate配置介绍
使用spring的jdbcTemplate进一步操作JDBC 一.普通配置 SpringJdbcTemplate连接数据库并操作数据 1.applicationContext.xml 1.1 建立D ...
- Spring经常使用属性的注入及属性编辑器
对于对象的注入,我们使用ref方式,能够指定注入的对象.以下看下对于基本类型的注入.以及当spring无法转换基本类型进行注入时,怎样编写一个相似转换器的东西来完毕注入. 一.基本类型的注入 以下写一 ...
- ros中文术语表及消息类型表
前言:整理一些ros常用表格,包括中文术语对照表. 一.中文术语表 二.消息类型表 -END-
- JQuery (总结)
延迟触发事件 Ajax异步请求数据 Jquery事件: Focus获得焦点 blur失去焦点 Change内容在变化的时候 Click点击事件 ---------------------------- ...
- oracle错误ORA-00604 递归sql级别1出现错误 ora-00942 表或试图不存在 ORA-06512 在line 11
错误截图如下: 搜索了很多方法,但是都没有办法解决,不过最终还是找到了一个好的解决办法, 多谢那位仁兄的博客[http://blog.itpub.net/519536/viewspace-689469 ...
- ZBrush通过遮罩得到子物体
ZBrush 中通过遮罩为模型添加子物体的方法简单且方便,我们可以通过按住Ctrl键绘制遮罩结合相关命令创建具有抽出厚度的模型提取出作为子物体附在模型表面.本文将详细介绍在Zbrush中如何通过遮罩得 ...
- 最近邻插值法&线性插值&双线性插值&三线性插值
最近邻插值法nearest_neighbor是最简单的灰度值插值.也称作零阶插值,就是令变换后像素的灰度值等于距它最近的输入像素的灰度值. 造成的空间偏移误差为像素单位,计算简单,但不够精确.但当图像 ...
- Android 7.0 Gallery图库源码分析2 - 分析启动流程
前面一讲解了Gallery启动Activity以及界面如何绘制,现在开始讲解启动流程的代码逻辑. GalleryActivity的onCreate方法中调用initializeByIntent()方法 ...
- 在用HTML+css写页面中遇到的问题
一.清除浮动. (1)verflow:hidden;这个CSS样式是大家常用到的CSS样式,但是大多数人对这个样式的理解仅仅局限于隐藏溢出,而对于清除浮动这个含义不是很 了解.一提到清除浮动,我们就会 ...