hdu 1305 Immediate Decodability
来源:互联网 发布:联合办公网络设计方案 编辑:程序博客网 时间:2024/05/21 17:28
和1671类似。
// File Name: hdu1305.cpp// Author: Toy// Created Time: 2013年05月08日 星期三 07时25分58秒#include <iostream>#include <cstdio>#include <cstring>#include <vector>#include <cctype>#include <cmath>#include <string>#include <algorithm>#include <cstdlib>#include <iomanip>#include <list>#include <map>#include <set>#include <deque>#include <stack>#include <utility>#include <bitset>#define L(x) x << 1#define R(x) x << 1 | 1using namespace std;const int sigma_size = 2;const int maxnode = 8 * 10 + 10;string st[100];int cnt, tmp;bool flag[15];struct Trie { int ch[maxnode][sigma_size]; int val[maxnode]; int sz; void clear ( ) { sz = 1; memset ( ch[0], 0, sizeof ( ch[0] ) ); } int idx ( char c ) { return c - '0'; } void insert ( string s, int v ) {int u = 0, n = s.length ();for ( int i = 0; i < n; ++i ) { int c = idx ( s[i] ); if ( !ch[u][c] ) {memset ( ch[sz], 0, sizeof ( ch[sz] ) );val[sz] = 0;ch[u][c] = sz++; } u = ch[u][c];}val[u] = v; } bool find ( string s, int cnt ) {int u = 0, n = s.length();for ( int i = 0; i < n; ++i ) { if ( s[i] == '\0' ) break; int c = idx ( s[i] ); if ( !ch[u][c] ) break; u = ch[u][c]; if ( val[u] == 1 && i != n - 1 ) flag[cnt]++;} }}trie;int main ( ) { tmp = cnt = 1; trie.clear(); memset ( flag, 0, sizeof ( flag ) ); while ( cin >> st[tmp] ) {if ( st[tmp] != "9" ) trie.insert ( st[tmp], 1 );else { for ( int i = 1; i <= tmp; ++i ) trie.find ( st[i], i ); bool cmp = 0; for ( int i = 1; i <= tmp; ++i ) if ( flag[i] ) cmp = 1; if ( cmp ) cout << "Set " << cnt++ << " is not immediately decodable" << endl; else cout << "Set " << cnt++ << " is immediately decodable" << endl; trie.clear(); tmp = 0; memset ( flag, 0, sizeof ( flag ) );}tmp++; } return 0;}
- HDU-1305-Immediate Decodability
- hdu 1305 Immediate Decodability
- hdu 1305 Immediate Decodability
- HDU-1305 Immediate Decodability
- hdu-1305 Immediate Decodability
- HDU 1305 Immediate Decodability
- hdu 1305 Immediate Decodability
- hdu 1305 Immediate Decodability
- HDU 1305 Immediate Decodability
- hdu-1305-Immediate Decodability
- HDU 1305:Immediate Decodability
- HDU 1305 Immediate Decodability
- HDU 1305 Immediate Decodability(二叉树)
- 杭电 hdu 1305 Immediate Decodability
- hdu 1305 Immediate Decodability(字典树)
- Hdu 1305 Immediate Decodability 字典树
- hdu 1305 Immediate Decodability(Trie树)
- 【水题-前缀码】HDU 1305 Immediate Decodability
- Hibernate 关系映射 —— 单向一对多
- ASP读取、添加、修改、删除数据库的代码
- 简化函数调用之五 :Parameterize Method(令函数携带参数)
- 程序人生之我们的故事:十年如歌(7)
- 简化函数调用之六 :Replace Parameter with Explicit Methods(以明确函数取代参数)
- hdu 1305 Immediate Decodability
- Android入门:调用WebService
- 什么是面向对象(1)
- pb使用msxml进行网页存取
- DROP DATABASE ORA-01504
- JAVA形参值传递,引用传递分析。
- 生成 guid 字符串化
- 简化函数调用之七 :Preserve Whole Object(保持对象完整)
- UIColor使用colorWithRed定义颜色