hdoj--5233--Gunner II(map+queue&&二分)
Gunner II
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1724 Accepted Submission(s): 631
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.
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.
5 5
1 2 3 4 1
1 3 1 4 2
1
3
5
4
2HintHuge input, fast IO is recommended.
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <stack>
#include<iostream>
using namespace std;
struct Node
{
int num,hight;
bool flg;
}a[110000];
bool cmp(Node x,Node y)
{
if(x.hight == y.hight )return x.num<y.num;
return x.hight<y.hight;
}
int b_search(int val,int len)
{
int l=0,r=len-1,mid;
while(l<=r)
{
mid=(l+r)/2;
if(a[mid].hight<val)l=mid+1;
else if(a[mid].hight == val && a[mid].flg == false)l=mid+1;
else r=mid-1;
}
return l;
}
int main()
{
int m,n,i,j,cy,ans,ji;
while(~scanf("%d %d",&n,&m))
{
for(i=0;i<n;i++)
{
scanf("%d",&a[i].hight);
a[i].num=i+1;
a[i].flg=true;
}
sort(a,a+n,cmp);
for(i=0;i<m;i++)
{
scanf("%d",&ji);
ans=b_search(ji,n);
a[ans].flg=false;
if(a[ans].hight==j)
printf("-1\n");
else
{
a[ans].flg=false;
cout<<a[ans].num<<endl;
}
}
}
return 0;
}
#include<cstdio>
#include<map>
#include<list>
#include<queue>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
int n,m;
while(~scanf("%d%d",&n,&m))
{
map<int,queue<int> >mp;
int tmd;
for(int i=1;i<=n;i++)
{
scanf("%d",&tmd);
mp[tmd].push(i);
}
while(m--)
{
scanf("%d",&tmd);
queue<int> &p=mp[tmd];
if(p.empty()) printf("-1\n");
else
{
printf("%d\n",p.front());
p.pop();
}
}
}
return 0;
}
hdoj--5233--Gunner II(map+queue&&二分)的更多相关文章
- HDU 5233 Gunner II 离散化
题目链接: hdu:http://acm.hdu.edu.cn/showproblem.php?pid=5233 bc(中文):http://bestcoder.hdu.edu.cn/contests ...
- hdu 5233 Gunner II
原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=5233 简单题,stl水之... #include<algorithm> #include& ...
- 二分查找 BestCoder Round #42 1002 Gunner II
题目传送门 /* 题意:查询x的id,每次前排的树倒下 使用lower_bound ()查找高度,f[i]记录第一棵高度为x树的位置,查询后+1(因为有序) */ #include <cstdi ...
- Gunner II(二分,map,数字转化)
Gunner II Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total ...
- Java中的容器类(List,Set,Map,Queue)
Java中的容器类(List,Set,Map,Queue) 一.基本概念 Java容器类类库的用途是“保存对象”,并将其划分为两个不同的概念: 1)Collection.一个独立元素的序列,这些元素都 ...
- Gunner II--hdu5233(map&vector/二分)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5233 题意:有n颗树,第 i 棵树的高度为 h[i],树上有鸟,现在这个人要打m次枪,每次打的高度是 ...
- hdoj 5199 Gunner map
Gunner Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5199 D ...
- HDOJ 5147 Sequence II 树阵
树阵: 每个号码的前面维修比其数数少,和大量的这后一种数比他的数字 再枚举每一个位置组合一下 Sequence II Time Limit: 5000/2500 MS (Java/Others) ...
- hdu5233 Gunner II
Problem Description Long long ago, there was a gunner whose name is Jack. He likes to go hunting ver ...
随机推荐
- Hive扩展功能(七)--Hive On Spark
软件环境: linux系统: CentOS6.7 Hadoop版本: 2.6.5 zookeeper版本: 3.4.8 主机配置: 一共m1, m2, m3这五部机, 每部主机的用户名都为centos ...
- [Windows Server 2008] 服务器安全加固
★ 欢迎来到[护卫神·V课堂],网站地址:http://v.huweishen.com★ 护卫神·V课堂 是护卫神旗下专业提供服务器教学视频的网站,每周更新视频.★ 本节我们将带领大家:服务器安全加固 ...
- VHDL_ADC之cic_diffcell
library IEEE; use ieee.std_logic_1164.all; use ieee.numeric_std.all; library edclib; use edclib.pkg_ ...
- dubbo之优雅停机
优雅停机 Dubbo 是通过 JDK 的 ShutdownHook 来完成优雅停机的,所以如果用户使用 kill -9 PID 等强制关闭指令,是不会执行优雅停机的,只有通过 kill PID 时,才 ...
- dos2unix xxx.sh
前几天写了一个Linux的自动化脚本,没有使用变量,就是一些Linux命令的集合 今天试着把一些相同的字段提出来用变量表示,然后在Linux里运行,就发现一直在报错: : command not fo ...
- How an SSL connection is established
An SSL connection between a client and server is set up by a handshake, the goals of which are: To s ...
- Requests库 更新中
1.获取网页内容 --- requests库 <需理解HTTP协议> >requests库的7个主要方法 方法 说明 requests.requests() 构造一个请求,支撑一 ...
- java中一个数组不能放不同数据类型的值
在java中,数组不能放不同数据类型的值. 方法一: 多态 定义数组类型的时候定义为父类,而存进数组为父类的子类 public class test2 { public static void mai ...
- CSS 选择器 知识点
<html> <head> <style type="text/css"> h1 > strong { /*子元素选择器 只选择自己 的子 ...
- Luogu P1187 3D模型
题目描述 一座城市建立在规则的n×m网格上,并且网格均由1×1正方形构成.在每个网格上都可以有一个建筑,建筑由若干个1×1×1的立方体搭建而成(也就是所有建筑的底部都在同一平面上的).几个典型的城市模 ...