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 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).
Doubleville,一个小镇在得克萨斯州,遭到了外星人。他们绑架了一些居民,并将它们带到飞船绕地球轨道运行。经过一番(相当不愉快的)人体实验,外星人克隆了受害者,然后把很多克隆人送回了Doubleville。所以,现在可能发生,有6个人名为Huge F.Bumblebee:原来的人,和5份克隆人。未经授权克隆的联邦调查局(FBUC)要求您确定每个人被克隆了多少份。为了帮助您,FBUC已经从每个人身上收集了DNA样本。同一个人的所有副本具有相同的DNA序列,不同的人有不同的序列(我们知道,这个镇上没有同卵双胞胎,这不是个问题)。
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 .
The input is terminated by a block with n = m = 0 .
输入的测试数据包含多块。每一块下第一行包含有两个整数:数字1≤N≤20000表示人数,
DNA序列的长度为1≤M≤20。接下来的n行包含的DNA序列:每行包含一个序列的m个字符,其中每个字符是'A','C','G'或'T'。
输入是由其中n = m = 0时的块终止。
输入是由其中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.
对于每个测试用例,你必须输出n行,
每一行包含一个整数。第一行包含未被克隆的人的数量。第二行包含只被复制一次的人(即,
每一个这样的人, 有两个相同的副本。)第三行中包含的人认为存在3个相同的人,依此类推人数:第i - th行表示有i个克隆人的那些人。例如,如果有11个样品,其中之一就是从
John Smith,和所有其余的都是从Joe Foobar的副本,那么你必须打印'1'在第一个变化与第十行,和'0'的所有其他行。
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
快排后做标记输出。。数据量小,可以直接进行数据累加输出,很水。。。
#include <iostream>
#include <stdio.h>
#include <string.h>
void q_sort(char dna[22222][22], int p, int r);
int partition_q(char dna[22222][22], int p, int r);
int main(void){
char DNA[22222][22];
int counter[22222];
int n, m, i, k;
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
while((scanf("%d %d", &n, &m) != EOF )&& !((n == 0) && (m == 0))){
for (i = 0;i < n; i++){
counter[i] = 0;
}
for (i = 0 ;i < n;i ++){
scanf("%s", DNA[i]);
}
q_sort(DNA, 0, n-1);
// for (i = 0;i < n;i ++){
// printf("%s\n", DNA[i]);
// }
k = 0;
for (i = 0;i < n;i ++){
if (strcmp(DNA[i], DNA[i+1]) == 0){
k ++;
}else{
counter[k] ++;
k = 0;
}
}
for (i = 0;i < n;i ++){
printf("%d\n", counter[i]);
}
}
return 0;
}
void q_sort(char dna[22222][22], int p, int r){
int q;
if (p <= r){
q = partition_q(dna, p, r);
q_sort(dna, p, q-1);
q_sort(dna, q+1, r);
}
}
int partition_q(char dna[22222][22], int p, int r){
char x[22], temp[22];
int i = p - 1;
int j;
strcpy(x, dna[r]);
for (j = p;j < r;j ++){
if (strcmp(dna[j], x) > 0){
i++;
strcpy(temp, dna[j]);strcpy(dna[j], dna[i]);strcpy(dna[i], temp);
}
}
strcpy(temp, dna[i+1]);strcpy(dna[i+1], dna[r]);strcpy(dna[r], temp);
return i+1;
}