hdu 6625 three array (01-trie)】的更多相关文章

链接:http://acm.hdu.edu.cn/showproblem.php?pid=5536 题面; Chip Factory Time Limit: 18000/9000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 6277    Accepted Submission(s): 2847 Problem Description John is a manager o…
大意: 给两个数组$a,b$, 要求重排使得$c_i=a_i\oplus b_i$字典序最小. 字典树上贪心取$n$次, 然后排序, 还不知道怎么证. #include <iostream> #include <sstream> #include <algorithm> #include <cstdio> #include <cmath> #include <set> #include <map> #include <…
链接:http://acm.hdu.edu.cn/showproblem.php?pid=4825 题面: Xor Sum Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 132768/132768 K (Java/Others)Total Submission(s): 6430    Accepted Submission(s): 2783 Problem Description Zeus 和 Prometheus 做了一个游戏,…
字典树中根到每个结点对应原串集合的一个前缀,这个前缀由路径上所有转移边对应的字母构成.我们可以对每个结点维护一些需要的信息,这样即可以去做很多事情. #10049. 「一本通 2.3 例 1」Phone List #include <bits/stdc++.h> using namespace std; namespace Trie { struct Node { Node *ch[]; int val; Node* clear() { ;i<;i++) ch[i]=NULL; val=…
Trie树是字符串问题中应用极为广泛的一种数据结构,可以拓展出AC自动机.后缀字典树等实用数据结构. 然而在此我们考虑0-1 Trie的应用,即在序列最大异或问题中的应用. 这里的异或是指按位异或.按位异或有很多重要的性质.比如可拆分性,每个位可以进行单独处理后线性合并得到最终结果. 同时按位异或也是可减的.比如0111 ^ 1010 = 1101, 那么 1101 ^ 1010 = 0111. 证明从略. 首先我们考虑0-1 Trie的版本,也就是 给定一个序列a[i], 每次询问一个数x与a…
Hash Array Mapped Trie   Python\hamt.c…
题意:给定两个长为n的数组a和b:重新排列a和b,生成数组c,c[i]=a[i] xor b[i]:输出字典序最小的c数组. 分析:将a中的数插入一颗01字典树a中:将b中的数插入一颗01字典树b中:在trie树上查找n次,每次同时在a和b中下移一层:if 能同时走0,则同时走0:else if 能同时走1,则同时走1:else if 树a能走0&&树b能走1,则a走0.b走1:else if 树a能走1&&树b能走0,则a走1.b走0:else 向c中插入一个新数为这两个…
Phone List Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 18217    Accepted Submission(s): 6120 Problem Description Given a list of phone numbers, determine if it is consistent in the sense th…
统计难题 Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131070/65535 K (Java/Others) Total Submission(s): 34909    Accepted Submission(s): 13109 Problem Description Ignatius最近遇到一个难题,老师交给他很多单词(只有小写字母组成,不会有重复的单词出现),现在老师要他统计出以某个字符串为前缀的单词数量(单词本身也是自己…
http://acm.hdu.edu.cn/showproblem.php?pid=2846 题意:给出N个模式串,再给出M个文本串,问每一个文本串在多少个模式串中出现. 思路:平时都是找前缀的,这里将模式串s[1……len]的每一个[i,len]的子串都插入,这样就可以满足条件.还要注意如果两个子串都为同一个模式串的子串,不能重复计数.可以用一个id数组装上一次是哪个串的id,如果id相同就不要重复计数了. #include <cstdio> #include <algorithm&g…
这是BC上的一道题,当时比赛没有做,回头看看题解,说是AC自动机,想着没有写过AC自动机,于是便试着抄抄白书的模板,硬是搞了我数个小时2000ms时限1800过了= = ! 这里就直接贴上BC的结题报告(#27):http://bestcoder.hdu.edu.cn/solutions.php 1003 Matching on Array 首先我们考虑m=1的情况.给定两个数组A={a1,a2,…,an}和B={b1,b2,…,bk},问B在A中出现了几次.令ci=ai+1ai,1≤i<n,同…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1251 题意:给你多个字符串,求以某个字符串为前缀的字符串数量. 思路:简单的trie数应用,在trie的数据结构中增加一个存储到当前节点字符串出现的次数,在插入的过程中维护即可. code: #include <cstdio> #include <cstring> ; struct TrieNode { int num; // 遍历到该结点形成的字符串出现的次数 TrieNode* n…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5635 LCP Array Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 282    Accepted Submission(s): 79 Problem Description Peter has a string s=s1s2..…
Bone Collector Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 60469    Accepted Submission(s): 25209 Problem Description Many years ago , in Teddy’s hometown there was a man who was called “Bo…
饭卡 Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 28562    Accepted Submission(s): 9876 Problem Description 电子科大本部食堂的饭卡有一种很诡异的设计,即在购买之前判断余额.如果购买一个商品之前,卡上的剩余金额大于或等于5元,就一定可以购买成功(即使购买后卡上余额为负),否则无…
多校10 1002 HDU 6172 Array Challenge 题意 There's an array that is generated by following rule. \(h_0=2,h_1=3,h_2=6,h_n=4h_{n-1}+17h_{n-2}-12h_{n-3}-16\) And let us define two arrays bnandan as below. $ b_n=3h_{n+1} h_n+9h_{n+1} h_{n-1}+9h_n^2+27h_n h_{n…
题意: 给一个集合,多次询问,每次给一个k,问你集合和k异或结果最大的哪个 题解: 经典的01字典树问题,学习一哈. 把一个数字看成32位的01串,然后查找异或的时候不断的沿着^为1的路向下走即可 #include <bits/stdc++.h> #define endl '\n' #define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0) #define rep(ii,a,b) for(int ii=a;ii<=b;++i…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 Many years ago , in Teddy’s hometown there was a man who was called “Bone Collector”. This man like to collect varies of bones , such as dog’s , cow’s , also he went to the grave …  The bone collect…
题目链接: hdu:http://acm.hdu.edu.cn/showproblem.php?pid=5234 bc:http://bestcoder.hdu.edu.cn/contests/contest_chineseproblem.php?cid=585&pid=1003 题解: 由于数据比较小,所以可以转化为判定性问题,即: dp[i][j][kk]表示走到i,j这一点时吃了kk重的蛋糕,转移方程只要考虑这一点的蛋糕吃和不吃两种情况(01背包) 代码: #include<iostr…
hdu 1574 RP问题 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1574 分析:01背包的变形. RP可能为负,所以这里分两种情况处理一下就好. 初始化要注意. #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; #define inf 0x3f3f3f3f int…
链接:http://acm.hdu.edu.cn/showproblem.php?pid=2546 思路:需要首先处理一下的的01背包,当饭卡余额大于等于5时,是什么都能买的,所以题目要饭卡余额最小,那预留5元(相当于饭卡余额为5)来买最贵的菜 然后对剩下n-1进行01背包dp才是正确的.但是还存在一个问题,那就饭卡初始余额小于5时,也要处理掉. 下面讲01背包(原型可以看大牛的背包九讲,本人也正在学习),定义dp[i][j]为买前i种菜品剩下j元时的最大消费值等于下面两中情况之一的值 有两种来…
Problem C Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 1196    Accepted Submission(s): 371 Problem Description 度熊手上有一本神奇的字典,你可以在它里面做如下三个操作: 1.insert : 往神奇字典中插入一个单词 2.delete: 在神奇字典中删除所有前缀等于…
Bone Collector Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 57334    Accepted Submission(s): 23933 Problem Description Many years ago , in Teddy’s hometown there was a man who was called “Bon…
题意 : 给出一个 n 行.m 列的方格图,现从图左上角(0, 0) 到右下角的 (n, m)走出一个字符串(规定只能往下或者往右走),向右走代表' R ' 向下走则是代表 ' D ' 最后从左上角到右下角,不同的路线会走出不同的字符串,问你这些不同的字符串有多少个是包含了接下来给定的两个子串. 分析 : 简单想想不难发现最后肯定是走了 (n+1) 个 ' D ' 和 (m+1)个 ' R ' ,那么也就是说用 (n+1) 个 ' D ' 和 (m+1)个 ' R ' 构造出长度为 (n+m+2…
原题代号:HDU 2602 原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 原题描述: Problem Description Many years ago , in Teddy’s hometown there was a man who was called “Bone Collector”. This man like to collect varies of bones , such as dog’s , cow’s , also…
目录 题意: 解析 原题描述 字典树动态求Mex @(hdu 6625求两个序列异或最小值的排列) 题意: \(T(100)\)组,每组两个长度为\(n(100000)\)的排列,你可以将\(a[]\)和\(b[]\)随机排列,可以得到\(c[i]=a[i]\)^\(b[i]\),求字典序最小的\(c[]\). 解析 一个显然对的贪心做法: 针对本题 每次两颗字典树同时往下走,如果都有\(0\)或者\(1\)这条路径,就随便同时走\(0\;or\;1\)这条路径,否则只能一个走\(0\),一个走…
GCD Array Time Limit: 11000/5500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 843    Accepted Submission(s): 205 Problem Description Teacher Mai finds that many problems about arithmetic function can be reduced to…
这种01背包的裸题,本来是不想写解题报告的.但是鉴于还没写过背包的解题报告.于是来一发. 这个真的是裸的01背包. 代码: #include <iostream> #include <cstdio> using namespace std; #define N 1007 int c[N],w[N],dp[N]; int main() { int t,i,n,V,v; scanf("%d",&t); while(t--) { scanf("%d%…
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1676 对顶点i,j,起点s=1,终点t=n,可以认为题意要求一组01矩阵use[i][j],使得aveCost=sigma(use[i][j]*cost[i][j])/sigma(use[i][j])最小,且{(i,j)|use[i][j]==1}是图的S-T割 定义F(e)=min(sigma(use[i][j]*(cost[i][j]-a))),明显,F(e)是目标式的变…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 水题啊水题 还给我WA了好多次 因为我在j<w[i]的时候状态没有下传.. #include <cstdio> #include <algorithm> #include <cstring> using namespace std; typedef long long LL; typedef pair<int,int> PII; #define PB…