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. 遗传奥秘的伟大揭秘者:J.Watson

    J.Watson的近照: 人们公认,揭秘生命体的遗传奥秘(DNA)是二十世纪最伟大的科技成果之中的一个,或许就是人类最伟大的科技进步(而不是"之中的一个"). 上世纪是人类做出伟大 ...

  2. Android Cocos2dx引擎 prv.ccz/plist/so等优化缓存文件,手把手ida教你逆向project反编译apk库等文件

    前段时间在 Android play 上看到一个非常牛逼的 3D 动态天气预报,效果真的非常炫.二话不说动手 dex2jar.bat/apktool 发现这并没 有什么卵用,在核心的地方看见 nati ...

  3. 【PLSQL】触发器trigger类型,状态,參数

    ************************************************************************   ****原文:blog.csdn.net/clar ...

  4. UVA 1541 - To Bet or Not To Bet 记忆化DP概率

    Alexander Charles McMillan loves to gamble, and during his last trip to the casino he ran across a n ...

  5. h5-弹出层layer,提示,顶部横条,

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAYkAAAI7CAIAAACWVfAJAAAgAElEQVR4nOy9f1ATWb733z3uOA4kIC ...

  6. Qt-信号和槽-多对多

    前言:介绍1对多,多对1以及多对多的案例. 一.1对多 演示内容:在QLineEdit输入时,同步label,text browser以及调试输出板同步显示. 1.1 新建工程 1.2 添加部件 拖入 ...

  7. 关于Angular官网《英雄指南》教程几点问题修正(此问题在2018年4月份有效,以后可能就订正了)

    1.官网中在导入“of”关键字时的引用为: import { Observable, of } from 'rxjs'; 应该改为: import { Observable } from 'rxjs/ ...

  8. mysql+spring+mybatis实现数据库读写分离[代码配置] .

    场景:一个读数据源一个读写数据源. 原理:借助spring的[org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource] ...

  9. C#中方向键与回车键切换控件焦点

    环境:界面上有TextBox,ComboBox等控件. 不建议把左右方向键都用来切换焦点,否则你在TextBox里面改变光标所在字符位置就不方便了. 方法一:笨方法,需为每个控件单独注册事件处理 以T ...

  10. activity_note

    在activiti任务中,主要分为两大类查询任务(个人任务和组任务): 1.确切指定了办理者的任务,这个任务将成为指定者的私有任务,即个人任务. 2.无法指定具体的某一个人来办理的任务,可以把任务分配 ...