ZOJ1808 POJ1056 HDU1305 Immediate Decodability,Trie树
2011-10-04 19:20
309 查看
标准的Trie树的题,有个小错误一直弄了很久,还是不熟练啊
/******************************************************************************* # Author : Neo Fung # Email : neosfung@gmail.com # Last modified: 2011-10-04 19:17 # Filename: ZOJ1808 POJ1056 HDU1305 Immediate Decodability.cpp # Description : ******************************************************************************/ // #include "stdafx.h" // #define DEBUG #include <fstream> #include <stdio.h> #include <iostream> #include <string.h> #include <string> #include <memory.h> using namespace std; #define KINDNUM 2 #define MAX 20000 struct TrieNode { bool isNum; TrieNode *next[KINDNUM]; }node[MAX],*head; int nodeInd; bool insert(TrieNode *&root,char *num) { TrieNode *location=root; int i=0,branch=0; if(location==NULL) { location=&node[nodeInd++]; location->isNum=false; for (int j=0;j<KINDNUM;++j) location->next[j]=NULL; root=location; } while(num[i]) { branch=num[i]-'0'; if(location->next[branch] && (!num[i+1] || location->next[branch]->isNum)) return false; else if(!(location->next[branch])) { location->next[branch]=&node[nodeInd++]; location->next[branch]->isNum=false; for (int j=0;j<KINDNUM;++j) location->next[branch]->next[j]=NULL; } ++i; location=location->next[branch]; if(!num[i]) location->isNum=true; } return true; } int main(void) { #ifdef DEBUG freopen("data.txt","r",stdin); #endif char str[15]; int ncase=1; while(gets(str) && strlen(str)!=0) { nodeInd=0; head=NULL; if(str[0]=='9') break; printf("Set %d ",ncase++); bool ans=insert(head,str); while(gets(str) && str[0]!='9') { if(ans) ans= ans&&insert(head,str); } if(ans) printf("is immediately decodable\n"); else printf("is not immediately decodable\n"); } return 0; }
相关文章推荐
- poj1056 & hdu1305 & zoj1808 Immediate Decodability(字典树变形)
- ZOJ 1109 Language of FatMouse (trie树)
- ZOJ 2346 Shortest Prefixes(trie树)
- zoj 1808 Immediate Decodability
- ZOJ 1808 Immediately Decodable
- ZOJ-1808
- zoj 1808 || poj 1056 IMMEDIATE DECODABILITY
- poj 3630 || zoj 2876 ||hdu 1671 Phone List (Trie树的应用)
- ZOJ 1808 Immediate Decodability(trie)
- ZOJ 2876 Phone List(trie树)
- ZOJ 3228 找AC自动机找来的TRIE树
- ZOJ2876 POJ3630 HDU1671 Phone List,静态Trie树
- ZOJ 1808 Immediately Decodable
- poj 3268 Silver Cow Party & zoj 2008 Invitation Cards
- ZOJ 1091 BFS
- ZOJ 3789 Abs Problem
- ZOJ----1610-Count the Colors(线段树)
- ZOJ 3981 && 2017CCPC秦皇岛 A:Balloon Robot
- zoj 2105 || poj 1385 Lifting the Stone
- zoj 1967 Fiber Network/poj 2570