[模拟][哈希]刷题计划
2018-01-30 16:11
281 查看
题目描述
Sample Input
10000 12
2 1
3
2 9999
3
1 1
3
2 1
3
2 10000
3
2 9999
3
Sample Output
1
9999 1
9999
9999
10000 9999
9999 10000
分析
其实很简单,只是要把AC的处理掉,陈旧记录处理掉而已
然后其实O(n)朴素查找明明可以,我却作死用哈希没错就好
Sample Input
10000 12
2 1
3
2 9999
3
1 1
3
2 1
3
2 10000
3
2 9999
3
Sample Output
1
9999 1
9999
9999
10000 9999
9999 10000
分析
其实很简单,只是要把AC的处理掉,陈旧记录处理掉而已
然后其实O(n)朴素查找明明可以,我却作死用哈希没错就好
#include <iostream> #include <cstdio> #define q 100037 using namespace std; int n,m; int hash[q],wrong[q]; int a[101]; bool w[101]; int locate(int x) { int i=x%q; while (hash[i%q]!=0&&hash[i%q]!=x) i++; return i%q; } void insert(int x) { int i=locate(x); hash[i]=x; } bool member(int x) { int i=locate(x); return hash[i]==x; } int loc(int x) { int i=x%q; while (wrong[i%q]!=0&&wrong[i%q]!=x) i++; return i%q; } void ins(int x) { int i=locate(x); wrong[i]=x; } void del(int x) { int i=loc(x); wrong[i]=0; } bool mem(int x) { int i=locate(x); return wrong[i]==x; } void init() { scanf("%d%d",&n,&m); } void doit() { int i,j,p,b,t=0; for (i=1;i<=m;i++) { scanf("%d",&p); if (p==1) { scanf("%d",&b); insert(b); for (j=1;j<=t;j++) if (a[j]==b) w[j]=1; if (mem(b)) del(b); } if (p==2) { scanf("%d",&b); if (member(b)) continue; if (mem(b)) for (j=1;j<=t;j++) if (a[j]==b) w[j]=1; t++; a[t]=b; ins(a[t]); } if (p==3) { int k=0; for (j=t;j>=1;j--) if (!w[j]) { printf("%d ",a[j]); k++; if (k==20) break; } printf("\n"); } } } int main() { freopen("problem.in","r",stdin); freopen("problem.out","w",stdout); init(); doit(); fclose(stdin); fclose(stdout); }
相关文章推荐
- NYOJ 2356 哈希计划(模拟)
- NYOJ 2356 哈希计划(模拟)
- NYOJ 2356: 哈希计划【模拟】
- NYOJ 2356 哈希计划(模拟)
- POJ训练计划2996_Help Me with the Game(模拟)
- [bzoj3207][花神的嘲讽计划Ⅰ] (字符串哈希+主席树)
- 【JZOJ 4309】【NOIP2015模拟11.4】刷题计划 刷题计划
- POJ训练计划3993_Emag eht htiw Em Pleh(模拟)
- POJ训练计划2632_Crashing Robots(模拟)
- 【模拟】津津的储蓄计划
- [NOIp复习计划]:模拟
- 【NOI2014模拟7.11】【WC2008游览计划加强】挖宝藏
- POJ1002 487-3279 直接哈希模拟
- 【雅礼联考GDOI2017模拟】Zjr506的捕猫计划
- JZOJsenior4740.【雅礼联考GDOI2017模拟9.2】Zjr506的捕猫计划
- 【模拟】洛谷 P1089 津津的储蓄计划
- 问题 C: 哈希计划
- 【BZOJ3874】[Ahoi2014]宅男计划【贪心】【模拟退火 / 三分法】
- 【模拟】津津的储蓄计划
- 第六章――根据执行计划优化性能(1)――理解哈希、合并、嵌套循环连接策略