博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POJ---2945 Find the Clones[字典树-简单题(多例输入注意删除)]
阅读量:4317 次
发布时间:2019-06-06

本文共 3652 字,大约阅读时间需要 12 分钟。

Find the Clones
Time Limit: 5000MS   Memory Limit: 65536K
Total Submissions: 6042   Accepted: 2263

Description

Doubleville, a small town in Texas, was attacked by the aliens. They have abducted some of the residents and taken them to the a spaceship orbiting around earth. After some (quite unpleasant) human experiments, the aliens cloned the victims, and released multiple copies of them back in Doubleville. So now it might happen that there are 6 identical person named Hugh F. Bumblebee: the original person and its 5 copies. The Federal Bureau of Unauthorized Cloning (FBUC) charged you with the task of determining how many copies were made from each person. To help you in your task, FBUC have collected a DNA sample from each person. All copies of the same person have the same DNA sequence, and different people have different sequences (we know that there are no identical twins in the town, this is not an issue).

Input

The input contains several blocks of test cases. Each case begins with a line containing two integers: the number 1 ≤ n ≤ 20000 people, and the length 1 ≤ m ≤ 20 of the DNA sequences. The next n lines contain the DNA sequences: each line contains a sequence of m characters, where each character is either `A', `C', `G' or `T'.
The input is terminated by a block with n = m = 0 .

Output

For each test case, you have to output n lines, each line containing a single integer. The first line contains the number of different people that were not copied. The second line contains the number of people that were copied only once (i.e., there are two identical copies for each such person.) The third line contains the number of people that are present in three identical copies, and so on: the i -th line contains the number of persons that are present in i identical copies. For example, if there are 11 samples, one of them is from John Smith, and all the others are from copies of Joe Foobar, then you have to print `1' in the first andthe tenth lines, and `0' in all the other lines.

Sample Input

9 6AAAAAAACACACGTTTTGACACACGTTTTGACACACACACACTCCCCCTCCCCC0 0

Sample Output

120100000

Hint

Huge input file, 'scanf' recommended to avoid TLE.

Source

 
 
 
 
第一边写完就感觉很好,不过交上去就MLE了,后来才发现没有删掉结构体。
第一次写析构delete,以后还是要多学习!
code:
1 #include
2 #include
3 using namespace std; 4 5 int n,m; 6 int cnt[20010]; 7 8 struct node 9 {10 int cnt;11 node *next[26];12 }*p;13 14 void build(char str[],int k,node *head)15 {16 while(k
next[str[k]-'A']!=NULL)19 {20 head->next[str[k]-'A']->cnt+=1;21 head=head->next[str[k]-'A'];22 }23 else24 {25 head->next[str[k]-'A']=new node;26 head=head->next[str[k]-'A'];27 for(int i=0;i<26;i++)28 head->next[i]=NULL;29 head->cnt=1;30 }31 if(k==strlen(str)-1)32 {33 if(head->cnt==1)34 cnt[1]++;35 else36 {37 cnt[head->cnt-1]--;38 cnt[head->cnt]++;39 }40 }41 k++;42 }43 }44 45 void del(node *head)46 {47 if(head==NULL)48 return;49 for(int i=0;i<26;i++)50 {51 del(head->next[i]);52 head->next[i]=NULL;53 }54 delete(head);55 return;56 }57 58 int main()59 {60 char str[30];61 while(~scanf("%d%d",&n,&m),n||m)62 {63 memset(cnt,0,sizeof(cnt));64 p=new node;65 for(int i=0;i<26;i++)66 p->next[i]=NULL;67 for(int i=0;i

 

转载于:https://www.cnblogs.com/XBWer/archive/2012/09/07/2674437.html

你可能感兴趣的文章
通过镜像下载Android系统源码
查看>>
python字符串格式化 %操作符 {}操作符---总结
查看>>
windows 不能在 本地计算机 启动 Apache
查看>>
iOS开发报duplicate symbols for architecture x86_64错误的问题
查看>>
Chap-6 6.4.2 堆和栈
查看>>
【Java学习笔记之九】java二维数组及其多维数组的内存应用拓展延伸
查看>>
C# MySql 连接
查看>>
网络抓包分析方法大全
查看>>
sql 数据类型
查看>>
android 截图
查看>>
WebServicer接口类生成方法。
查看>>
POJ 1740
查看>>
【翻译】火影忍者鸣人 疾风传 终级风暴2 制作介绍
查看>>
http和webservice
查看>>
hdu1879------------prim算法模板
查看>>
jdbc之二:DAO模式
查看>>
MySQL性能优化方法一:缓存参数优化
查看>>
Angular2 - 概述
查看>>
正则表达式tab表示\t
查看>>
NodeJS+Express+MongoDB 简单实现数据录入及回显展示【Study笔记】
查看>>