poj 2945 Find the Clones

LLC谐振变换器中的软开关艺术:ZVS与ZCS的协同设计 本文深入解析了LLC谐振变换器如何通过巧妙的电路设计,协同实现零电压开关(ZVS)与零电流开关(ZCS),从而大幅降低开关损耗与电磁干扰,提升电源效率。文章结合设计实战,详细阐述了谐振参数计算、器件选型及调试避坑指南,为高效、高功率密度电源设计提供了核心思路与解决方案。 阅读详情

Find the Clones
Time Limit: 5000MS Memory Limit: 65536K
Total Submissions: 7145 Accepted: 2659

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. 


题目链接:http://poj.org/problem?id=2945


题目大意:给出n行由m个大写字母'A','G','T','C'组成的“基因片段”,输出n行,第i行输出基因片段重复出现i次的基因片段的个数。


解题思路:字典树+哈希。每个基因片段插入完成后在最后一个节点的cnt加1,表示该基因片段重复的次数,hash[cnt]++,表示重复出现cnt次的基因片段的个数。因为cnt的值是在更新的,所以当hash[cnt]值大于0时,要更新cnt值就要把原来hash[cnt]的值减去一个。


代码如下:


#include <cstdio>
#include <cstring>
char s[22];
int hash[20002];
struct node
{
    node *next[26];
    int cnt;
    node()
    {
        memset(next,0,sizeof(next));
        cnt=0;
    }
};
void Inseart(node *p,char *s)
{
    for(int i=0;s[i]!='\0';i++)
    {
        int a=s[i]-'A';
        if(p->next[a]==NULL)
            p->next[a]=new node();
        p=p->next[a];
    }
    if(hash[p->cnt])   //需要更新cnt值时hash值也要更新
        hash[p->cnt]--;
    p->cnt++;
    hash[p->cnt]++;
}
void clear(node *p)  //这题要释放空间,否则会超出内存
{
	for(int i=0;i<26;i++)
		if(p->next[i])
			clear(p->next[i]);
	delete p;
}

int main()
{
    int n,i,m;
    while(scanf("%d%d",&n,&m)&&(n||m))
    {
		node *root=new node();
        memset(hash,0,sizeof(hash));
        for(i=0;i<n;i++)
        {
            scanf("%s",s);
            Inseart(root,s);
        }
        for(i=1;i<=n;i++) //第i行输出重复出现次数为i的基因片段的个数。
        printf("%d\n", hash[i]);
		clear(root);
    }
	return 0;
}



VMware ESXi 系统里创建虚拟机,虚拟磁盘日志损坏,如何或者把数据备份? 🏆本文收录于《全栈Bug调优(实战版)》专栏,主要记录项目实战过程中所遇到的Bug或因后果及提供真实有效的解决方案,希望能够助你一臂之力,帮你早日登顶实现财富自由🚀;同时,欢迎大家关注&&收藏&&订阅!持续更新中,up!up!up!! 阅读详情

相关推荐

西门子【Automation Framework V1.2】AF架构:从软件栈到高效自动化项目的构建蓝图

本文深入解析西门子Automation Framework V1.2 (AF架构) 的核心价值与实施蓝图。该框架通过定义标准化的软件栈(如TIA Portal V19、STEP7、WinCC Unified)和严格的安装配置流程,将自动化项目开发从依赖个人经验的“手工作坊”模式,转变为高效、可复制的工业化模式。遵循此架构,工程师能快速构建稳定可靠的项目基础,规避环境冲突,从而专注于核心工艺与逻辑设计,大幅提升团队协作与项目交付效率。

weixin_29230059的博客 443

poj2945

Find the Clones Time Limit:5000MS Memory Limit:65536K Total Submissions:5391 Accepted:1998 Description Doubleville, a small town in Texas, was attacked by t...

weixin_33967071的博客 204

vue 获取el-table多选的选中行

<el-table :data='tableData' ref="multipleTable" v-loading='loading' border max-height='700' style='width: 100%' size="mini"> <el-table-column type="selection" width="55"></el-table-column> <el-table-column label

且听风吟的博客 6653

nyoj 285-寻找克隆人

http://acm.nyist.net/JudgeOnline/problem.php?pid=285 寻找克隆人 时间限制:1000 ms  |  内存限制:65535 KB 难度:3 描述 美国的一个小镇近日被外星人袭击,一部分居民被其带走并克隆,现在,科学家提取了镇上一些人的DNA,请找出其中具有相同被克隆个数的DNA个数,例如下面的9个序列

shofe的学习随记 837

RV1126上YOLOv8部署实战:从模型转换到板端推理的完整避坑指南

本文提供了在瑞芯微RV1126芯片上部署YOLOv8目标识别算法的完整实战指南。内容涵盖从模型转换、环境搭建到板端推理代码编写的全流程,重点解析了RKNN-Toolkit使用、量化配置、内存优化及后处理实现等关键环节的常见问题与解决方案,旨在帮助开发者高效避坑,实现边缘AI应用的稳定落地。

pz89012345的博客 577

FPGA时序约束:从时钟树到数据路径的深度解析与优化策略

本文深入解析FPGA时序约束的核心技术与优化策略,涵盖时钟树结构分析、时序报告解读和数据路径优化。重点探讨Vivado工具中的时序约束方法,包括时钟定义、异常约束和物理优化,帮助工程师掌握寄存器级时序分析和系统级协同设计,实现高性能FPGA设计。

u5v6w7的博客 655

poj 2945-关于字符串的排序

Find the Clones Time Limit: 5000MS   Memory Limit: 65536K Total Submissions:6265   Accepted: 2328 Description Doubleville, a small town in Texas, was attacked by the al

桑榆 733

Python逆向爬取Tik Tok,MsToken,X-Bogus以及signature

tiktok作为字节海外的自媒体平台,具有很非常大的价值,本文旨在教会大家实现Tik Tok的签名获取以及数据的最终爬取。

weixin_74305707的博客 3282

oj网站的训练题:统计字符

题目描述: 输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数。 样例输入: a 1, 样例输出: 1 1 1 1 参考代码: #include #include int main() { int letter=0,space=0,number=0,other=

一个程序猿的修炼之路 480

Matlab 轴承信号仿真+分析

文章目录项目说明1、信号仿真1.1 仿真公式1.2 信号参数设置1.3 代码实现2、仿真信号分析2.1 小波变换2.2 快速谱峭度 项目说明 本文主要解决两个问题: 1、仿真包含周期性冲击信号、随机干扰冲击信号、调制干扰信号以及随机噪声四个成分的故障轴承信号; 2、使用小波变换以及快速谱峭度对该仿真信号进行分析。 1、信号仿真 1.1 仿真公式 这里的仿真信号公式主要参考了包文杰学者的硕士论文《加权谱峭度故障诊断方法研究与应用》,列举公式如下: 周期性冲击信号仿真 随机干扰冲击信号仿真 调制

cocofisher的博客 9274

可编程逻辑控制器(PLC)系列:Mitsubishi MELSEC-Q_(8).MELSEC-Q系列PLC故障诊断与维护

MELSEC-Q系列PLC的故障诊断与维护是一个系统性的过程,需要工程师具备扎实的理论基础和丰富的实践经验。通过了解故障类型、使用诊断工具、遵循诊断步骤,可以有效地定位和解决故障问题。同时,定期的检查与保养、备份与恢复、优化程序和配置,以及提供良好的运行环境,可以减少故障的发生,提高系统的可靠性。希望本文能够帮助工程师在故障诊断与维护过程中更加得心应手,确保MELSEC-Q系列PLC的稳定运行。

2401_87715305的博客 1253

杭电ACM2017:字符串统计

#include <iostream> using namespace std; int main(){ int n, count = 0; char a[100]; cin >> n; while (n){ cin >> a; for (int i = 0; a[i] != '\0'; i++){ if (a[

咸鱼 1513

OpenClaw零基础教程:30分钟搭建你的第一个AI自动化助手

别再看那些满是代码、专业术语的教程了,那些都是给程序员看的。这篇教程,我把所有步骤拆到了极致,你跟着点鼠标就行,点错了都没关系,大不了重装一遍,5分钟的事。

2601_94871597的博客 104

POJ 2945 Find the Clones

题目描述 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)

CS练功房 1006

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

poj 2945 Find the Clones

Find the Clones Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 6663   Accepted: 2475 Description Doubleville, a small town in Texas, was attacked by the ali

liu_fanyi3的专栏 623

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

POJ2945——Find the Clones

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 unpleas

Alex 661

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

POJ2945 Find the Clones trie树

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

184

POJ 2945 Find the Clones

原题 http://poj.org/problem?id=2945 题目大意: 找出字符串相同的个数为1的有几种,2的有几种,n的有几种。 简单的排序加比较。用一次快排就可以了。#include <iostream> #include"string.h" #include"cstdio" #include"stdlib.h" #include"algorithm"using namespac

ShineRoyal 538

POJ 2945 Find the Clones Hash

题目大意:给出一些字符串,问其中n个一样的有多少。 思路:看discuss里各种神奇的方法啊,什么map啊,什么Trie啊。这题不是一眼Hash么。。难道是我想错了? 任意hash方法将所有字符串hash然后排序,之后统计一下相同的有多少就行了,500+MS水过。。 PS:明天就是NOIP我这么水真的好( CODE: #include #include #incl

(╯°口°)╯(┴—┴ 747

POJ2945 Find the Clones Tire树

题目大意:给出n个人的DNA序列,这些序列长度相同且不大于20,让找出重复k次的DNA的个数,其中,k=1,2,...n。 分析:这道题的处理方法很多,比较普遍的有用STL中的map的,有快排的,也有Tire树的。我试了下map的,怎么优化都是TLE,在网上找了“别人AC的代码”交也是TLE,严重怀疑这种方法的可行性啊。不过还是把代码贴出来了,可以参考一下: map代码如下(TLE版)

AC_Gibson的专栏 483

POJ 2945 - Find the Clones(字典树)

题目: http://poj.org/problem?id=2945 题意: n个长度为m的字符串,求出重复 1~n次的字符串的个数。 思路: 字典树。 AC. #include #include #include using namespace std; const int M = 4e5+5000; int wp, pi; struct node { int

Halo 563

POJ 2945 Find the Clones 水

Find the Clones Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 7524   Accepted: 2789 Description Doubleville, a small town in Texas, was attacked by the alien

MY Blog 1313

poj 2945 Find the Clones (map+string,hash思维)

Find the Clones Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 7498   Accepted: 2780 Description Doubleville, a small town in Texas, was attacked by the ali

ysCover 929

POJ2945 Find the Clones(暴力 & 字典树)

Find the Clones Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 7501   Accepted: 2782 Description Doubleville, a small town in Texas, was attacked by the a

GKHack's Blog 1135

POJ2945 Find the clones

传送门 Trie树的模板题。我们把每个人都存在Trie树里面,然后再每个人跑一遍即可。注意一个人走过之后要清零,否则的话会被重复计算。 #include<cstdio> #include<algorithm> #include<cstring> #include<iostream> #include<cmath> #in...

weixin_30919429的博客 163
上一篇: hdu 1251 统计难题
下一篇: HDU 5135 Little Zu Chongzhi's Triangles
雨狮子
博客等级 码龄12年 24粉丝 185原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址