题目链接

B - 秋实大哥与快餐店

Time Limit:1000MS     Memory Limit:65535KB     64bit IO Format:%lld & %llu

Appoint description: 
System Crawler  (2016-04-24)

Description

朝为田舍郎,暮登天子堂。秋实大哥从小就怀抱有远大的理想,所以他开了一家快餐店。

秋实大哥根据菜的口感,给每一道菜一个唯一的CID,同时对于前来的客人,根据他们的口味喜好,秋实大哥会给每一个客人一个PID。

对于一个标号为PID的客人,他对标号为CID的菜的喜爱程度为PID∧CID(∧表示按位异或),该值越大表示越喜欢。

秋实大哥实在太忙了,现在他需要你来帮忙照看一下他的店铺。

Input

第一行包含一个整数n,表示秋实大哥的餐馆内现在有n道菜。

接下来一行包含n个整数,分别表示每一道菜的CID。

接下来一行包含一个整数m,表示接下来发生了m件事。

接下来的m行,每一行为以下两种事件之一:

0 c : 表示秋实大哥最新研制出一道标号为c的菜
1 p : 表示来了一位标号为p的客人,请你在已有的菜中找出一道他最喜爱的菜

1≤n,m≤100000,0≤PID,CID≤1000000。

Output

对于每一个p事件输出一个整数,表示该客人最喜欢的菜的标号。

Sample Input




1 1 
0 2 
1 1

Sample Output

1

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <set>
using namespace std;
typedef long long ll;
typedef unsigned long long Ull;
#define MM(a,b) memset(a,b,sizeof(a));
const double eps = 1e-;
const int inf = 0x3f3f3f3f;
const double pi=acos(-);
const int maxn=;
struct data{
int l,r,id,flag;
}tree[(<<)+]; void insertc(int x)
{
int ptr=;
for(int i=;i>=;i--)
{
if(x&(<<i))
{
tree[ptr].r=;
ptr=*ptr+;
}
else
{
tree[ptr].l=;
ptr=*ptr;
}
}
tree[ptr].id=x;
}
//在字典树中插入字符
int findc(int x)
{
int ptr=;
for(int i=;i>=;i--)
{
if(x&(<<i))
{
if(tree[ptr].l)
ptr=*ptr;
else ptr=*ptr+;
}
else
{
if(tree[ptr].r)
ptr=*ptr+;
else ptr=*ptr;
}
}
return tree[ptr].id;
}
//查找字符
int main()
{
int n,m;
while(~scanf("%d",&n))
{
MM(tree,);
int x,y;
for(int i=;i<=n;i++)
{
scanf("%d",&x);
insertc(x);
} scanf("%d",&m);
for(int i=;i<=m;i++)
{
scanf("%d %d",&x,&y);
if(!x) insertc(y);
else printf("%d\n",findc(y));
}
}
return ;
}

分析:字典树处理,注意开的数组的大小,是将1e6用trie树存储,转化成二进制2^20>=1e6,

比如(2^20)1000...(20个0),

  

 

CDOJ 1060 秋实大哥与快餐店 字典树 水题的更多相关文章

  1. 2015 UESTC 数据结构专题C题 秋实大哥与快餐店 字典树

    C - 秋实大哥与快餐店 Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/show/59 ...

  2. CDOJ 1057 秋实大哥与花 线段树 区间更新+区间查询

    链接: I - 秋实大哥与花 Time Limit:1000MS     Memory Limit:65535KB     64bit IO Format:%lld & %llu Submit ...

  3. UESTC - 1057 秋实大哥与花 线段树模板题

    http://acm.uestc.edu.cn/#/problem/show/1057 题意:给你n个数,q次操作,每次在l,r上加上x并输出此区间的sum 题解:线段树模板, #define _CR ...

  4. UESTC_秋实大哥与快餐店 2015 UESTC Training for Data Structures<Problem C>

    C - 秋实大哥与快餐店 Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) Sub ...

  5. D - 秋实大哥与快餐店

    秋实大哥与快餐店 Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) Submit  ...

  6. hdu1305 字典树水题

    题意:      给你一些字符串,然后问你他们中有没有一个串是另一个串的前缀. 思路:       字典树水题,(这种水题如果数据不大(这个题目不知道大不大,题目没说估计不大),hash下也行,把每个 ...

  7. CDOJ 1070 秋实大哥打游戏 带权并查集

    链接 F - 秋实大哥打游戏 Time Limit:1000MS     Memory Limit:65535KB     64bit IO Format:%lld & %llu Submit ...

  8. CDOJ 1069 秋实大哥去打工 单调栈 下标处理

    E - 秋实大哥去打工 Time Limit:1000MS     Memory Limit:65535KB     64bit IO Format:%lld & %llu Submit St ...

  9. CDOJ 1059 秋实大哥与小朋友 STL(set)+离散化+BIT区间更新单点查询

    链接: A - 秋实大哥与小朋友 Time Limit:1000MS     Memory Limit:65535KB     64bit IO Format:%lld & %llu Subm ...

随机推荐

  1. 查找两个有序数组中的第K个元素(find kth smallest element in 2 sorted arrays)

    查找两个有序数组中的第K个元素 int FindKth(int a[], int b[], int k, int astart, int aend, int bstart, int bend) { ; ...

  2. AspNet Core Swagger4.0 生成请求model描述

    今天给大家分享 swagger 俩个冷门的小技巧 获取控制器描述 将 IncludeXmlComments 方法第二个参数设置为 true 即可 public static void IncludeX ...

  3. 01:kubernetes基础

    1.1kubernetes简介   参考博客:https://www.kubernetes.org.cn/k8s 1.kubernetes介绍 1. Kubernetes是容器集群管理系统,是一个开源 ...

  4. hadoop-组件

    hadoop1.x 和 hadoop2.x 区别 HDFS 分布式文件存储系统 优点   缺点 MapReduce 分布式计算 详见我的博客 mapreduce YARN 计算资源管理器 主要了解两个 ...

  5. str 小列题

    name = " aleX leNb "#2.有变量 完成如下操作: 移除 name 变量对应的值两边的空格,并输出处理结果 name=name.strip() print(nam ...

  6. Dynamic Compilation and Loading of .NET Objects

      This is another approach to dynamic compilation of objects and their usage via Interfaces. Introdu ...

  7. 68. Text Justification (JAVA)

    Given an array of words and a width maxWidth, format the text such that each line has exactly maxWid ...

  8. 【vue】iView-admin2.0动态菜单路由【版2】

    依照iView-admin2.0动态菜单路由[版1] 归纳几个节点动态路由获取方式2 ——> easymock假数据 ——> 数据转组件处理.addRoutes ——> localS ...

  9. 【转】rsa公钥和私钥的生成

    转:https://www.cnblogs.com/zengsf/p/10136886.html 在liunx环境中 openssl 然后生成私钥: genrsa -out app_private_k ...

  10. enums应用详解

    枚举类: 获取枚举相关值: