Find the Clones
Time Limit: 5000MS   Memory Limit: 65536K
Total Submissions: 8490   Accepted: 3210

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 6
AAAAAA
ACACAC
GTTTTG
ACACAC
GTTTTG
ACACAC
ACACAC
TCCCCC
TCCCCC
0 0

Sample Output

1
2
0
1
0
0
0
0
0

Hint

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

Source

大致题意:求1到n中有i个相同的字符串有多少种.
分析:字符串很多,直接hash或者map可能会爆掉,但是每个字符串长度很小,可以用trie,最后统计结尾标记的个数即可.
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; int n, len, tot, ans[];
char s[]; struct node
{
int tr[];
int end;
void clear()
{
memset(tr, , sizeof(tr));
end = ;
}
}e[]; void insert(char *ss)
{
int u = ;
for (int i = ; i <= len; i++)
{
if (!e[u].tr[ss[i] - 'A'])
e[u].tr[ss[i] - 'A'] = ++tot;
u = e[u].tr[ss[i] - 'A'];
}
e[u].end++;
} int main()
{
while (scanf("%d%d", &n, &len) && (n || len))
{
memset(ans, , sizeof(ans));
for (int i = ; i <= tot; i++)
e[i].clear();
tot = ;
for (int i = ; i <= n; i++)
{
scanf("%s", s + );
insert(s);
}
for (int i = ; i <= tot; i++)
ans[e[i].end]++;
for (int i = ; i <= n; i++)
printf("%d\n", ans[i]);
} return ;
}

poj2945 Find the Clones的更多相关文章

  1. POJ2945 Find the Clones trie树

    建一颗$trie$树(当然你哈希也资瓷),边插边更新,看看搜到最底时有多少个字符串,然后更新. #include<cstdio> #include<iostream> #inc ...

  2. POJ2945(Find the Clones)--字典树,map

    题意:给你n个规定长度的单词,问你其中出现了1次的单词,出现两次的单词...出现n次单词分别有多少个. 当然这题map也能过,但是这里介绍字典树的做法. 首相对于n个单词存入树中,当然建树过程中遇到一 ...

  3. POJ2945:Find the Clones——题解

    http://poj.org/problem?id=2945 还是trie树……对于结束标记累加并且开个数组记录一下即可. #include<cstdio> #include<cst ...

  4. Find the Clones

    Find the Clones Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 6365   Accepted: 2375 D ...

  5. poj 2945 Find the Clones

    https://vjudge.net/problem/POJ-2945 题意: 给出n个长度相同的DNA序列,如果一个DNA序列出现过两次,那么就有说明它被复制了一次.问被复制0次,1次,2次--n- ...

  6. Apache Tomcat 9 Installation on Linux (RHEL and clones)

    Apache Tomcat 9 is not available from the standard RHEL distributions, so this article provides info ...

  7. XVII Open Cup named after E.V. Pankratiev Stage 14, Grand Prix of Tatarstan, Sunday, April 2, 2017 Problem D. Clones and Treasures

    题目:Problem D. Clones and TreasuresInput file: standard inputOutput file: standard outputTime limit: ...

  8. 【hdu2222】【poj2945】AC自动机入门题

    HDU2222 传送门 题目分析 裸题:注意构建自动机用的是模式串,思想和kmp很类似. code: #include<iostream> #include<cstdio> # ...

  9. 用链式字典树解决POJ2945

    首先,我们的思路是用链式的字典树结构,解决poj2945这道题 题意是,统计所有的字符串出现的次数,并依次输出各个次数的数量 例如: input 9 6AAAAAAACACACGTTTTGACACAC ...

随机推荐

  1. 使用Kubernetes里的job计算圆周率后2000位

    使用Kubernetes里的job(作业),我们可以很方便地执行一些比较耗时的操作. 新建一个job.ymal文件: 定义了一个Kubernetes job,名称为pi,类型为job,容器名称为pi, ...

  2. 微信程序开发系列教程(四)使用微信API创建公众号自定义菜单

    大家可能经常看到一些微信公众号具有功能强大的自定义菜单,点击之后可以访问很多有用的功能. 这篇教程就教大家如何动手做一做. 这个教程最后实现的效果是:创建一个一级菜单"UI5", ...

  3. 文字自动自左向右滚动的js代码

    重要的一点,就是scrollLeft一直在变化.对象一直在移动,参照物没有动. 代码: css: #div1{display:black;width:110px;height:50px;line-he ...

  4. java 核心技术卷一笔记 6 .1接口 lambda 表达式 内部类

    6.1 接口不是类,是对类的一组需求的描述,这些类需要遵守接口描述的统一格式进行定义.例如:Arrays类中sort方法(可以对对象数组进行排序)前提是对象所属的类必须实现了Comparable 接口 ...

  5. 如何在Ubuntu 16.04上安装Apache Web服务器

    转载自:https://www.howtoing.com/how-to-install-the-apache-web-server-on-ubuntu-16-04 介绍 Apache HTTP服务器是 ...

  6. java实现中文或其他语言及标点符号等转换成unicode字符串,或unicode的16进制码转换回文字或符号等

    package org.analysisitem20181016.test; public class Code128Test2019052201 { public static final Stri ...

  7. PAT (Basic Level) Practise (中文)-1034. 有理数四则运算(20)

    PAT (Basic Level) Practise (中文)-1034. 有理数四则运算(20)  http://www.patest.cn/contests/pat-b-practise/1034 ...

  8. SQLyog连接数据库 提示错误plugin caching_sha2_password could not be loaded

    1.打开mysql cmd 2.执行语句 ALTER USER 'root'@'localhost' IDENTIFIED BY 'password' PASSWORD EXPIRE NEVER; # ...

  9. shell脚本,编写1个弹出式菜单的shell程序并实现其简单的菜单功能。

    [root@localhost wyb]# cat zonghe.sh #!/bin/bash #zonghe usage(){ case $choice in ) read -p "ple ...

  10. 初涉KMP算法

    久仰字符串系列理论 KMP 讲解(引用自bzoj3670动物园) 某天,园长给动物们讲解KMP算法. 园长:“对于一个字符串S,它的长度为L.我们可以在O(L)的时间内,求出一个名为next的数组.有 ...