HDU5233 Gunner II && BestCoder Round #42
来源:互联网 发布:tor网络原理 编辑:程序博客网 时间:2024/05/21 07:46
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5233
解题思路:
先对数据进行离散化,把数字转化到0 到n−1 的区间内。然后对每一种数字串起来按照ID从小到大。可以用链表,或者Vector。查询的时候要注意如果没有把查询一起离散化的话要先判断一下数字是否可以找得到。找到之后按照下标去对应的数字串中找出第一个即可。然后删除。如果数字串中没有数字了就应该输出−1 。空间复杂度是O(n) ,时间复杂度是nlogn+Qlogn
#include <iostream>#include <cstdio>#include <algorithm>using namespace std;int n,m;int p[100005];struct node{ int a,b,vis;}v[100005];bool cmp(node x,node y){ if(x.b == y.b) return x.a<y.a; return x.b<y.b;}int bitfind(int l,int r,int x){ if(l == r) { if(v[l].b==x && !v[l].vis) { v[l].vis=1; return v[l].a; } else return -1; } int mid=(l+r)>>1; if(v[mid].b<x || (v[mid].b==x && v[mid].vis)) return bitfind(mid+1,r,x); else return bitfind(l,mid,x);}int main(){ while(scanf("%d%d",&n,&m)!=EOF) { int i,j,x,ans=0; for(i=1;i<=n;i++) { scanf("%d",&x); v[i].a=i; v[i].b=x; v[i].vis=0; } sort(v+1,v+n+1,cmp); for(j=1;j<=m;j++) { scanf("%d",&x); int tmp=bitfind(1,n,x); p[ans++]=tmp; } for(i=0;i<ans;i++) printf("%d\n",p[i]); } return 0;}
0 0
- HDU5233 Gunner II && BestCoder Round #42
- hdu5233 Gunner II
- hdu 5233- Gunner II(BestCoder Round #42)离散化
- BestCoder Round #36(Gunner-hash)
- HDU5233 Gunner II 离散化的各种方法
- 【BestCoder】 HDOJ 5233 Gunner II
- BestCoder Round #36 HDU 5199 Gunner
- 【BestCoder】HDU 5199 Gunner
- hdu 5233 Gunner II
- hdu 5233 Gunner II
- hdu 5233 Gunner II
- HDU5233
- HDU5147 Sequence II && BestCoder Round #23 1002
- Bestcoder Round#43pog loves szh II
- BestCoder Round #42
- BestCoder Round #42
- BestCoder Round #42
- 【BestCoder】36 B Gunner(哈希)
- 十一周——继承与派生——阅读程序(4)
- JQ banner复习!!
- JDK动态代理
- 第十二周 阅读程序(4)
- 大数据应用于市场与用户研究
- HDU5233 Gunner II && BestCoder Round #42
- 使用Intent获取系统联系人
- 如何偷淘宝主图-淘宝偷图秘决
- 详解C#委托,事件与回调函数
- You need to use a Theme.appcompat theme with this activity
- 518抽奖软件:极简主义设计的践行者
- 中国的阶层变化
- 大三面试狗的种种
- 黑马程序员——java语言基础部分——网络编程