hdu5233 Gunner II
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.
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)
The id starts from 1.
1 2 3 4 1
1 3 1 4 2
3
5
4
2
#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的更多相关文章
- Gunner II(二分,map,数字转化)
Gunner II Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total ...
- 二分查找 BestCoder Round #42 1002 Gunner II
题目传送门 /* 题意:查询x的id,每次前排的树倒下 使用lower_bound ()查找高度,f[i]记录第一棵高度为x树的位置,查询后+1(因为有序) */ #include <cstdi ...
- hdu 5233 Gunner II
原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=5233 简单题,stl水之... #include<algorithm> #include& ...
- HDU 5233 Gunner II 离散化
题目链接: hdu:http://acm.hdu.edu.cn/showproblem.php?pid=5233 bc(中文):http://bestcoder.hdu.edu.cn/contests ...
- hdoj--5233--Gunner II(map+queue&&二分)
Gunner II Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Tot ...
- HDU5233
Gunner II Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total ...
- 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 ...
- 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 ...
- 函数式Android编程(II):Kotlin语言的集合操作
原文标题:Functional Android (II): Collection operations in Kotlin 原文链接:http://antonioleiva.com/collectio ...
随机推荐
- Mac pycharm更换版本后打不开
1.第一步:先输入: cd /Applications/PyCharm.app/Contents/MacOS 2.第二步:查看无法打开pycharm的原因,需要输入:c./pycharm 3.第三 ...
- 物理STANDBY库创建还原点(打开为read write后再变回主库)
开启STANDBY库为READ WRITE 1.取消主库传送归档 SQL> alter system set log_archive_dest_state_2=defer; 2.取消备库应用日志 ...
- missing tables and indexes的处理办法
最近做了SAP系统的异构迁移,顺便把oracle DB也升级了,从10g升级到11g,但是升级后,在DB02或者是ora_space中的diagnostics->Missing Tables a ...
- 视图V_160M和表T_160M的维护
今天发现一个视图,通过SM30居然无法维护,这个视图就是V_160M,表为T_160M,是采购相关的系统消息, 不过别着急,有办法维护的,呵呵,看下面: 试一试OMCQ这个事物代码吧! 分享出来,给需 ...
- mysql半同步复制跟无损半同步区别
mysql半同步复制跟无损半同步复制的区别: 无损复制其实就是对semi sync增加了rpl_semi_sync_master_wait_point参数,来控制半同步模式下主库在返回给会话事务成功之 ...
- SQL 语法速成手册
本文针对关系型数据库的一般语法.限于篇幅,本文侧重说明用法,不会展开讲解特性.原理. 一.基本概念 数据库术语 数据库(database) - 保存有组织的数据的容器(通常是一个文件或一组文件). 数 ...
- 前端PDF文件转图片方法
第一步:先下载pdfjs,网址:PDF下载地址,再引入到项目中,我是标签直接引用的 <script src="pdfjs/build/pdf.js"></scri ...
- Ubuntu对接GlusterFS
存储节点部署示例环境,仅供参考 主机名 IP 系统 gfs01 10.10.10.13 Ubuntu 16.04.3 LTS gfs02 10.10.10.14 Ubuntu 16.04.3 LTS ...
- 安卓开发视频教程!想找工作的你还不看这份资料就晚了!Android校招面试指南
前言 准备面试其实已经准备了挺久了,当时打算面试准备了差不多以后,跟公司谈谈涨薪的事情,谈不拢的话,就年后直接找其他的公司.谁想到婚假还没休完,老板就在公司宣布了撤出上海的决定,愿意去深圳的就去,不愿 ...
- CentOS安装mysql、JDK、Tomcat部署环境
1.1. 安装mysql-5.6 1.1.1. 检测系统内部有没有安装其他的mysql数据库 $ rpm -qa | grep mysql 1.1.2. 如果内部有需要先删除Mysql $ yum r ...