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 ...
随机推荐
- ajax不跳转页面的快速删除操作,可添加美观样式
以前我们讲的删除是利用嵌入php代码,跳转到另一个页面,从而降低了删除速度,但我们今天讲的利用ajax不仅可以达到不跳页面快速删除,并且能添加特效来美化页面. 上代码,我们先来做主页面 <!DO ...
- html5——3D转换
角度旋转 rotateX:默认以center绕x轴旋转 rotateY:默认以center绕y轴旋转 rotateZ:默认以cente绕z轴r旋转 //rotateX原点为center==>正值 ...
- jQuery——链式编程与隐式迭代
链式编程 1.原理:return this; 2.通常情况下,只有设置操作才能把链式编程延续下去.因为获取操作的时候,会返回获取到的相应的值,无法返回 this. 3.end():结束当前链最近的一次 ...
- JS——tab切换
排它思想: 1.先让所有的元素恢复默认值 2.再让选中的元素赋专有的值 3.干掉所有人,剩下我一个 <!DOCTYPE html> <html> <head lang=& ...
- CSS——text-indent
在h1标签里套入a标签并写上文字,有利于seo,但是文字如何隐藏呢?一般都是a标签变成内联块并首行缩进为负值. <!DOCTYPE html> <html lang="en ...
- SQL基本操作——GROUP BY
GROUP BY 语句用于结合合计函数,根据一个或多个列对结果集进行分组. SQL GROUP BY 实例:我们拥有下面这个 "Orders" 表 O_Id OrderDate O ...
- [Windows Server 2008] Serv-U安全设置
★ 欢迎来到[护卫神·V课堂],网站地址:http://v.huweishen.com ★ 护卫神·V课堂 是护卫神旗下专业提供服务器教学视频的网站,每周更新视频. ★ 本节我们将带领大家:Serv- ...
- 从JavaScript的单线程执行说起
先看一段代码: 1 2 3 4 5 setTimeout(function(){ alert("a"); }, 0); while(1); alert("b&qu ...
- nagios 插件ndoutils 安装配置
nagios 插件ndoutils 安装配置 原文地址:http://www.cnblogs.com/caoguo/p/5022645.html # Nagios install ndoutils # ...
- codeforces_725C_字符串
C. Hidden Word time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...