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 ...
随机推荐
- XSS-labs通关挑战(xss challenge)
XSS-labs通关挑战(xss challenge) 0x00 xss-labs 最近在看xss,今天也就来做一下xss-labs通过挑战.找了好久的源码,终于被我给找到了,因为在GitHub上 ...
- ruby+watir安装指南
安装ruby+watir一共需要下面几个步骤 1. 安装ruby: 2. 升级Rubygems:Rubygems(简称 gems)是一个用于对 Ruby组件进行打包的 Ruby 打包系统. 它提供一个 ...
- MySQL select 子查询的使用
### 子查询 >where 这个值是计算出来的 >本质:`在 where 语句中嵌套一个子查询语句` ```sql /*============== 子查询 ============== ...
- ctfshow—web—web5
打开靶机,代码审计 附上代码 <?php error_reporting(0); ?> <html lang="zh-CN"> <head> & ...
- SAP demo包 示例程序
在SAP的这个开发类中SABAPDEMOS,存放了N多的demo程序 有空的时候,可以看看.
- Linux Ubuntu系统版本通过Crontab设置定时任务的执行
Linux Ubuntu系统版本通过Crontab设置定时任务的执行 本文由本人收集网络信息总结而来 特别鸣谢:https://linux.zone/2258 1 crontab 简单介绍以及语法使用 ...
- Ubuntu20.04安装Typora
Ubuntu20.04安装Typora 安装方法 # optional, but recommended sudo apt-key adv --keyserver keyserver.ubuntu.c ...
- 使用Canal作为mysql的数据同步工具
一.Canal介绍 1.应用场景 在前面的统计分析功能中,我们采取了服务调用获取统计数据,这样耦合度高,效率相对较低,目前我采取另一种实现方式,通过实时同步数据库表的方式实现,例如我们要统计每天注册与 ...
- 2021/1/20随记,MTU
背景: 事情是这样的,客户2台防火墙部署了ipsec,内网互通,但是其中ssh以及其他大命令之类的操作就会卡住,简单的vi命令可以使用. 解决: 排除网络问题,因为内网互通,其次是系统层面问题,最终定 ...
- 使用Linux服务器来通过网络安装和激活Windows 7 —— 一些基本原理
使用Linux服务器来通过网络安装和激活Windows 7 -- 一些基本原理 https://www.pufengdu.org/blog/?p=372