POJ3283+字典树
来源:互联网 发布:悉知和知悉有什么区别 编辑:程序博客网 时间:2024/05/18 03:46
简单的字典树 模拟一遍。。
/*字典树构造字典树。*/#include<stdio.h>#include<string.h>#include<stdlib.h>#include<algorithm>#include<iostream>#include<queue>#include<map>#include<stack>#include<set>#include<math.h>using namespace std;typedef long long int64;//typedef __int64 int64;typedef pair<int64,int64> PII;#define MP(a,b) make_pair((a),(b)) const int maxn = 53;const int maxm = 100005;const int inf = 0x7fffffff;const double pi=acos(-1.0);const double eps = 1e-8;int a[ maxm ];struct tree{tree* next[ maxn ];//bool lev;};tree root;int tot;int getval(char mod[],char aim){ int i; for(i=0;mod[i];i++) { if(mod[i]==aim)return i; } return -1;}int getval(char s[]){ char value[15]="A234567891JQK"; char suit[10]="CDHS"; int a=getval(value,s[0]); int len=strlen(s); int b=getval(suit,s[len-1]); return a*4+b;}void init(){tot = 0;for( int i=0;i<maxn;i++ )root.next[i] = NULL;//printf("AC=%d\n",getval("AC"));//printf("AC=%d\n",getval("AD"));//printf("AC=%d\n",getval("AH"));//printf("AC=%d\n",getval("AS"));//printf("KS=%d\n",getval("KS"));}void build( int n ){tree *p = &root;tree *tmp;for( int i=1;i<=n;i++ ){if( p->next[ a[i] ]==NULL ){tmp = ( tree* )malloc( sizeof( root ) );//tmp->lev = true;for( int j=0;j<maxn;j++ ){tmp->next[j] = NULL;}p->next[ a[i] ] = tmp;p = p->next[ a[i] ];tot++;} else{p = p->next[ a[i] ];}}return ;} int main(){int m;//freopen("in.txt","r",stdin);//freopen("out.txt","w",stdout);while( scanf("%d",&m)&&m>0 ){int n;init();char tmp[ 12 ];for( int i=1;i<=m;i++ ){scanf("%d",&n);//printf("i=%d\n",i);for( int j=n;j>=1;j-- ){scanf("%s",tmp);a[ j ] = getval(tmp);}//for( int j=1;j<=n;j++ )//printf("%d ",a[j]);//printf("\n");build( n );}printf("%d\n",tot);//delete(&root);}return 0;}
- POJ3283+字典树
- POJ3283 Card Hands(字典树)
- 字典树
- 字典树
- 字典树
- 字典树
- 字典树
- 字典树。。
- 字典树
- 字典树
- 字典树
- 字典树
- 字典树
- 字典树
- 字典树
- 字典树
- 字典树
- 字典树
- Struts2学习笔记集锦
- Cocos2d-x cURL简单示例demo
- L2TP介绍
- android简单小游戏——打地鼠
- 多校第七场
- POJ3283+字典树
- HD 2037 今年暑假不AC 解题报告
- pomelo sync在lordofpomleo的使用分析
- VPN技术介绍
- python 文件的使用
- Linux和DOS命令对比
- 技术面试时,那些令人心虚的问题
- linux线程相关函数
- zoj 3725