bzoj11741174: [Balkan2007]Toponyms 字典树
来源:互联网 发布:淘宝视频收费标准 编辑:程序博客网 时间:2024/05/21 22:51
貌似是裸的。。。。。。上vfk大神的码。
#include <iostream>#include <cstdio>using namespace std;inline int getint(char *p){while ('0' > *p || *p > '9')p++;int res = *p++ - '0';while ('0' <= *p && *p <= '9')res = res * 10 + *p++ - '0';return res;}template <class T>inline void relax(T &a, const T &b){if (b > a)a = b;}const int MaxNNode = 3000000;inline bool isLetter(char c){return ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z') || c == ' ';}struct node{node *son, *brother;int size;char val;inline node *next(char c){for (node *i = son; i; i = i->brother)if (i->val == c)return i;return NULL;}};node pool[MaxNNode];node *tail;node *root;inline node *addNext(node *p, char c){node *q;if (tail != pool + MaxNNode)q = tail++;elseq = new node;q->son = NULL, q->size = 0;q->val = c, q->brother = p->son, p->son = q;return q;}inline void trie_init(){tail = pool;root = tail++;}inline char *trie_insert(char *s){node *p = root;root->size++;while (isLetter(*s)){node *next = p->next(*s);if (!next)next = addNext(p, *s);p = next;p->size++;s++;}return s;}int best = 0;void dfs(node *p, const int &depth){relax(best, p->size * depth);for (node *i = p->son; i; i = i->brother)dfs(i, depth + 1);}int main(){//freopen("1174.in", "r", stdin);//freopen("1174.out", "w", stdout);const int BufferSize = 10 * 1024 * 1024;static char buffer[BufferSize + 1];int bufferLen = fread(buffer, 1, BufferSize, stdin);buffer[bufferLen] = '\0';char *pRead = buffer;int n = getint(pRead);trie_init();for (int i = 0; i < n; i++){while (!isLetter(*pRead))pRead++;pRead = trie_insert(pRead);}dfs(root, 0);cout << best << endl;return 0;}
0 0
- bzoj11741174: [Balkan2007]Toponyms 字典树
- BZOJ P1174[Balkan2007]Toponyms
- BZOJ 1174: [Balkan2007]Toponyms
- 1174: [Balkan2007]Toponyms
- BZOJ1174 [Balkan2007] Toponyms 邻接链表优化 TRIE树
- 求助:BZOJ 1174: [Balkan2007]Toponyms (隐藏题)
- 【BZOJ】【P1176】【Balkan2007】【Mokia】【题解】【树状数组套平衡树】
- 【Balkan2007】Mokia
- 【BZOJ 1176】 [Balkan2007]Mokia
- bzoj 1176: [Balkan2007]Mokia
- 1176: [Balkan2007]Mokia
- [BZOJ1176] [Balkan2007]Mokia
- BZOJ1170 Balkan2007 Cipher
- BZOJ1173 Balkan2007 Point
- BZOJ1170: [Balkan2007]Cipher|hash
- 【bzoj1176】[Balkan2007]Mokia
- bzoj1176: [Balkan2007]Mokia
- bzoj1176【Balkan2007】Mokia
- Calendar 的学习与运用
- Android开发(33) Android中有关handler的使用(一)
- Struts 2 之资源国际化
- POJ 2253 Frogger最短路(floyd)
- 【BZOJ 1758】 [Wc2010]重建计划
- bzoj11741174: [Balkan2007]Toponyms 字典树
- 电话与短信服务(附源码)
- (转)unity文件存储和读取
- oracle round() 保留小数点后的0 --------类似sum()
- SEAndroid安全机制中的进程安全上下文关联分析
- 搭建JBPM4.4+tomcat+eclipse开发环境
- 工作的步骤-1-2-3-4-一种工作方法论
- commons-pool实战之 GenericObjectPool和GenericKeyedObjectPool
- 监控MongoDB状态