UVA 12937 字典树
来源:互联网 发布:乔丹贝尔体测数据 编辑:程序博客网 时间:2024/05/17 23:14
#include <iostream>#include <stdio.h>#include <math.h>#include <cmath>#include <vector>#include <map>#include <string>#include <string.h>#include <set>#include <queue>#include <algorithm>#include <sstream>#include <queue>using namespace std;typedef long long LL ;int n , a , b ;const int nodeSize = 300000 * 50 + 8 ;std::vector<int>lable[nodeSize] ;int _next[nodeSize][2] ;struct Tire{ int root ; int totel ; int newNode(){ _next[totel][0] = _next[totel][1] = 0 ; lable[totel].clear() ; return totel++ ; } void clear(){ totel = 0 ; root = newNode() ; } void add(LL x , int id){ int now = root ; int son ; for(int i = 0 ; i < n ; i++){ if(x & (1LL<<i)) son = 1 ; else son = 0 ; if(! _next[now][son]) _next[now][son] = newNode() ; now = _next[now][son] ; } lable[now].push_back(id) ; } int find(LL x , int id){ int now = root ; int son ; for(int i = 0 ; i < n ; i++){ if(x & (1LL<<i)) son = 1 ; else son = 0 ; son ^= 1 ; if(! _next[now][son]) return 0 ; now = _next[now][son] ; } int res = 0 ; for(std::vector<int>::iterator it = lable[now].begin() ; it != lable[now].end() ; it++){ if(id - *it >= a && id - *it <= b) res++ ; } return res ; }} ;const int N = 300008 ;LL sum[N] ;char light[58] ;Tire tree ;int main(){ int m , ca = 1 ; LL x ; while(scanf("%d%d%d%d" , &n , &m , &a , &b) != EOF){ sum[0] = 0 ; for(int i = 1 ; i <= m ; i++){ scanf("%s" , light) ; x = 0 ; for(int j = 0 ; j < n ; j++){ if(light[j] == '1') x |= (1LL<<j) ; } sum[i] = sum[i-1] ^ x ; } LL res = 0 ; tree.clear() ; tree.add(0LL , 0) ; for(int i = 1 ; i <= m ; i++){ res += tree.find(sum[i] , i) ; tree.add(sum[i] , i) ; } printf("Case %d: %lld\n" , ca++ , res) ; } return 0 ;}
0 0
- UVA 12937 字典树
- uva 11488 字典树
- UVA 11488 字典树
- UVA 12506(字典树)
- UVa 1401 字典树+DP
- UVA 11732 链式字典树
- UVA 11732 - strcmp() Anyone? 字典树
- UVa:1401 Remember the Word(字典树)
- UVA 11732 strcmp() Anyone?(字典树Trie)
- uva 11732 strcmp() Anyone? 字典树
- uva 11732 - strcmp() Anyone?(字典树)
- uva 11488 - Hyper Prefix Sets(字典树)
- uva 1519 - Dictionary Size(字典树)
- uva 1556 - Disk Tree(字典树)
- uva 1385 - Billing Tables(字典树)
- UVA Immediate Decodability(简单字典树)
- UVA 11732 "strcmp()" Anyone?(字典树)
- Uva 11732 "strcmp()" Anyone? (字典树)
- 《Motion Design for iOS》(十)
- stm32之DMA彻底研究
- ThinkPHP3.2.3关闭调试模式及做些修改
- Android的Activity屏幕切换动画
- 面试题45:圆圈中最后剩下的数字(约瑟夫环问题)
- UVA 12937 字典树
- 斯坦福大学 iOS 开发公开课总结
- UFLDL 08 Softmax Regression
- oracle的常用函数 instr() 和 substr()函数
- WebView 基本设置
- [2016,arXiv] An Enhanced Deep Feature Representation for Person Re-identification
- 全球最杰出的14位程序员
- 数据库总结
- Junit代码