Find the Clones
Time Limit: 5000MS |
|
Memory Limit: 65536K |
Total Submissions: 7498 |
|
Accepted: 2780 |
Description
Doubleville, a small in Texas, is attacked by the aliens. They has 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 then it might happen that there is 6 identical person named Hugh F. Bumblebee:the original person and its 5 copies. The Federal Bureau of unauthorized cloning (FBUC) charged you and the task of determining how many copies were made from Each person. To the your task, Fbuc has collected a DNA sample from each person. All copies of the same person has the same DNA sequence, and different people has different sequences (we know that ther E is no identical twins in the town, this is not a issue).
Input
The input contains several blocks of test cases. Each case begins with a line containing the integers:the number 1≤n≤20000 people, and the length 1≤m≤20 of the DN A 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 the to output n lines, each line containing a single integer. The first line contains the number of different people this were not copied. The second line contains the number of people so were copied only once (i.e., there is, identical copies for each SU CH person.) The third line contains the number of people that is present in three identical copies, and so on:the i-th line contain s the number of persons that is present in I identical copies. For example, if there was one samples, one of the them is from John Smith, and all the others was from copies of Joe Foobar, th En you has to print ' 1 ' in the first andthe tenth lines, and ' 0 ' with all of the other lines.
Sample Input
9 6AAAAAAACACACGTTTTGACACACGTTTTGACACACACACACTCCCCCTCCCCC0 0
Sample Output
120100000
Hint
Huge input file, ' scanf ' recommended to avoid TLE.
Source
Title Link: http://poj.org/problem?id=2945
The main idea: give some gene fragments, calculate the number of the same gene fragments, to find the number of occurrences.
Problem solving idea: Map+hash water problem, this question I also wrote with the dictionary tree, see the Dictionary tree classification.
The code is as follows:
#include <cstdio> #include <iostream> #include <cstring> #include <map> #include <string> using namespace std;map <string,int>mp;const int maxn=20005;int ans[maxn];int main (void) {//freopen ("In.txt", "R" , stdin), int n,m;while (scanf ("%d%d", &n,&m)!=eof&& (n+m)) {int Cnt=0;memset (ans,0,sizeof (ans)); for ( int i=0;i<=n;i++) mp.clear (); for (int i=0;i<n;i++) {char s[25];scanf ("%s", s); string a=s;ans[mp[a]]--; The number of the same number of genes changed, the number of occurrences of the number minus 1, changed after the addition of 1mp[a]++;ans[mp[a]]++;} for (int i=1;i<=n;i++) printf ("%d\n", Ans[i]);}}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
POJ 2945 Find The Clones (Map+string,hash thinking)