POJ 1056 解题报告
2015-09-04 01:51
393 查看
1056和之前的3630是一样的。
thestoryofsnow | 1056 | Accepted | 1420K | 0MS | C++ | 1727B |
/* ID: thestor1 LANG: C++ TASK: poj3630 */ #include <iostream> #include <fstream> #include <cmath> #include <cstdio> #include <cstring> #include <limits> #include <string> #include <vector> #include <list> #include <set> #include <map> #include <queue> #include <stack> #include <algorithm> #include <cassert> using namespace std; const int MAXL = 10 + 1; const int MAXN = 10000 * MAXL; class Trie { public: Trie *next[2]; bool isLeaf; Trie() { init(); } void init() { for (int i = 0; i < 2; ++i) { next[i] = NULL; } isLeaf = false; } }; Trie trie[MAXN]; bool insert(Trie *root, char number[], Trie trie[], int &trieNo) { bool isConsistent = false; for (int i = 0; number[i] != '\0'; ++i) { int next = number[i] - '0'; // we have never been here in this test case if (root->next[next] == NULL) { isConsistent = true; root->next[next] = &trie[trieNo]; trie[trieNo].init(); // assert (root->next[next]->version < t); trieNo++; } root = root->next[next]; // some words end here, so they are prefixes of this number if (root->isLeaf) { return false; } } root->isLeaf = true; return isConsistent; } int main() { char number[MAXL]; Trie *root = &trie[0]; root->init(); bool isConsistent = true; int trieNo = 1; int t = 1; while(scanf("%s", number) > 0) { if (strcmp(number, "9") == 0) { if (isConsistent) { printf("Set %d is immediately decodable\n", t); } else { printf("Set %d is not immediately decodable\n", t); } root->init(); isConsistent = true; trieNo = 1; t++; } else { if (isConsistent && !insert(root, number, trie, trieNo)) { isConsistent = false; } } } return 0; }
相关文章推荐
- clearcase 中一些概念和操作
- clearcase 中一些概念和操作
- C/C++ Resources
- C/C++ Resources
- Android test---robotium----简单例子
- [LeetCode#241]Different Ways to Add Parentheses
- Linux I/O 重定向详解及应用实例
- c/c++ 直接使用动态库 dlopen
- Linux I/O 重定向详解及应用实例
- c/c++ 直接使用动态库 dlopen
- c++ __declspec关键字详细用法
- c++ __declspec关键字详细用法
- c++ try throw catch
- c++ try throw catch
- Sudoku Solver
- 第一次写博客...
- c friend -- 友元
- c++ virturn function -- 虚函数
- c friend -- 友元
- c++ virturn function -- 虚函数