CDOJ 数据结构训练 J
来源:互联网 发布:钢铁侠反应堆淘宝 编辑:程序博客网 时间:2024/06/05 15:46
#include <map>#include <set>#include <list>#include <cmath>#include<cctype>#include <ctime>#include <deque>#include <stack>#include <queue>#include <cstdio>#include <string>#include <vector>#include <cstdlib>#include <cstring>#include <iostream>#include <algorithm>#define LL long long#define PI 3.1415926535897932626using namespace std;int gcd(int a, int b){return a % b == 0 ? b : gcd(b, a % b);}typedef struct node{ int value;//当前长度 int num;//当前字符的个数 struct node* child[2];}Node;LL max1;Node * root;Node * addnew(){ Node *p=(Node*)malloc(sizeof(Node)); p->num=0; p->value=0; p->child[0]=p->child[1]=NULL; return p;}void insert(char *str1){ int n,i,w; n=strlen(str1); Node *p=root; for (i=0;i<n;i++) { w=str1[i]-'0'; if (p->child[w]==NULL) { p->child[w]=addnew(); p->child[w]->value=i+1; p->child[w]->num++; } else { p->child[w]->num++; } p=p->child[w]; }}void slove(Node * p){ if (p==NULL) return ; if (p->num * p->value>max1) max1=p->num*p->value; for (int i=0;i<2;i++) slove(p->child[i]); return ;}void destroy(Node *p){ for (int i=0;i<2;i++) { destroy(p->child[i]); free(p->child[i]); }}int main(){ long N;char input[210]; root=(Node*)malloc(sizeof(Node)); while (scanf("%ld",&N)==1) { root->child[0]=root->child[1]=NULL; root->num=root->value=0; for (int i=0;i<N;i++) { scanf("%s",input); insert(input); } max1=0; slove(root); printf("%lld\n",max1); } return 0;}
0 0
- CDOJ 数据结构训练 J
- CDOJ 数据结构训练K
- CDOJ 数据结构训练 E
- cdoj 2015数据结构专题:J - Islands
- CDOJ 数据结构训练F 树状数组
- CDOJ 数据结构训练H 树状数组离散化
- UESTC数据结构专题训练 G,H,I,J
- CDOJ 搜索专题训练A
- cdoj 2015数据结构专题:K - Sliding Window
- 数据结构训练
- TJU训练赛—J
- ZCMU新人训练赛J
- ZCMU新人训练赛J
- CDOJ 训练搜索专题G 八数码固定终点问题
- SDUT14级队员训练1 J - Box
- BNU hnust训练赛 J特殊运算
- Codeforces 474A (五一训练 J)+
- CSU-ACM2017暑期训练3 J
- Git使用入门
- 索引扫描方式
- 百度技术沙龙 - 广告数据上的大规模机器学习
- CDOJ 数据结构训练K
- SlidingMenu getSupportActionBar()方法不能用
- CDOJ 数据结构训练 J
- virtualbox 中的linux 共享文件 发生文件系统类型错误的解决办法
- CDOJ 数据结构训练H 树状数组离散化
- [C++基础]原码/反码/补码、二进制位运算
- CDOJ 数据结构训练F 树状数组
- apk反编译修改
- CDOJ 数据结构训练 E
- UC编程9-管道pipe操作和共享内存段shm操作
- 在vim配置文件中添加对Python的支持