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
这道题因为删除方法不对,一直T,终于改用vis后,900多ms水过去了。。
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<vector>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<algorithm>
using namespace std;
struct node{
int id,num;
}a[100006];
int n,vis[100006]; bool cmp(node a,node b){
if(a.num==b.num)return a.id>b.id;
return a.num<b.num;
}
int q[100006]; int find(int x,int l,int r)
{
int mid,j;
while(l<=r)
{
mid=(l+r)/2;
if(a[mid].num==x)break;
if(a[mid].num>x)r=mid-1;
else l=mid+1;
}
j=mid;
if(vis[j]==1){
j--;
while(1){
if(vis[j]==0)break;
j--;
}
return j;
}
else{
j++;
while(1){
if(j>n || vis[j]==1 || a[j].num>x){
j--;break;
}
j++;
}
return j;
}
} int main()
{
int m,i,j,k;
while(scanf("%d%d",&n,&m)!=EOF)
{
map<int,int>hash;
hash.clear();
for(i=1;i<=n;i++){
vis[i]=0;
scanf("%d",&a[i].num);
a[i].id=i;
hash[a[i].num]++;
}
sort(a+1,a+1+n,cmp);
for(i=1;i<=m;i++){
scanf("%d",&q[i]);
if(hash[q[i]]==0){
printf("-1\n");continue;
}
else{
hash[q[i]]--;
j=find(q[i],1,n);
vis[j]=1;
printf("%d\n",a[j].id);
}
}
}
return 0;
}

hdu5233 Gunner II的更多相关文章

  1. Gunner II(二分,map,数字转化)

    Gunner II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total ...

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

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

  3. hdu 5233 Gunner II

    原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=5233 简单题,stl水之... #include<algorithm> #include& ...

  4. HDU 5233 Gunner II 离散化

    题目链接: hdu:http://acm.hdu.edu.cn/showproblem.php?pid=5233 bc(中文):http://bestcoder.hdu.edu.cn/contests ...

  5. hdoj--5233--Gunner II(map+queue&&二分)

     Gunner II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Tot ...

  6. HDU5233

    Gunner II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total ...

  7. Leetcode 笔记 113 - Path Sum II

    题目链接:Path Sum II | LeetCode OJ Given a binary tree and a sum, find all root-to-leaf paths where each ...

  8. Leetcode 笔记 117 - Populating Next Right Pointers in Each Node II

    题目链接:Populating Next Right Pointers in Each Node II | LeetCode OJ Follow up for problem "Popula ...

  9. 函数式Android编程(II):Kotlin语言的集合操作

    原文标题:Functional Android (II): Collection operations in Kotlin 原文链接:http://antonioleiva.com/collectio ...

随机推荐

  1. python模块详解 | progressbar

    参考官方文档:https://pypi.org/project/progressbar/#description progressbar 安装: pip install progressbar pro ...

  2. 【原创】X86_64汇编、寄存器、内嵌汇编

    整理的X86_64/X86汇编.寄存器.C内嵌汇编笔记,主要用于查阅使用. 目录 一.汇编语言 二.指令 数据传输指令 栈操作指令 push pop 运算指令 位操作 比较操作指令 标志寄存器 流控制 ...

  3. 【Linux】1、命令行及命令参数

    命令行及命令参数 文章目录 命令行及命令参数 1.命令行提示符 2.命令和命令参数 简单的命令 date ls 命令参数 短参数(一个字母) 长参数(多个字母) 参数的值 其它参数 3.小结 4.参考 ...

  4. gears-绕过rbash

    0x00 信息收集 0x01 smb攻击 crunch 生成密码的一个软件 @%%,这个是给的密码参数. crunch 4 4 -t @%%, -o words 最小4位,最长 4位 fcrackzi ...

  5. 05--Docker对DockerFile解析

    一.是什么: 1.1 DockerFile是用来构建Docker镜像的构建文件,是由一系列命令和参数构成的脚本 1.2 构建步骤: 1.2.1 编写Dockerfile文件 1.2.2 docker ...

  6. Sgu149 Computer Network

    Sgu149 Computer Network 题目描述 给你一棵N(N<=10000)个节点的树,求每个点到其他点的最大距离. 不难想到一个节点到其他点的最大距离为:max(以它为根的子树的最 ...

  7. Mybatis Plus 3.4版本之后分页插件的变化

    一.MybatisPlusInterceptor 从Mybatis Plus 3.4.0版本开始,不再使用旧版本的PaginationInterceptor ,而是使用MybatisPlusInter ...

  8. 拒演"拼命工作"的苦情戏,如何更聪明地提高工作效率?

    前几天PDD的事情又把互联网打工人的工作状态推向了大众视野,引起了大家的口诛笔伐.但是目前来看这种愤慨终究是暂时的,作用甚微.在大环境短时间无法改变的前提下,想想如何应对,或许比在网上愤愤不平破口大骂 ...

  9. ROS教程(一):ROS安装教程(详细图文)

    ros教程:ros安装 目录 前言 一.版本选择 二.开始安装 2.1 软件中心配置 2.2 添加源 2.3 安装 三.验证ROS 前言 关于ROS(Robot OS 机器人操作系统),估计看这个教程 ...

  10. MySQL如何加锁控制并发

    目录 前言 一.乐观锁 添加version字段 二.悲观锁 读锁 全表锁(LOCK TABLE 表 READ) 行锁(SELECT ... LOCK IN SHARE MODE) 写锁 全表锁(LOC ...