Question connection: http://acm.hdu.edu.cn/showproblem.php? Pid = 1, 1800
It means there are several pilots who need to practice flight on a broom. Each pilot has a different level, and a high level pilot can be a teacher of a low level pilot, each pilot has at most one teacher and only one student. Pilots with relationships between teachers and students can practice on the same broom, and this property is passed. That is to say, if there are five pilots A, B, C, D, and E, and the level is A> B> C> D> E, then A can be A teacher of B, B is the teacher of C, E is the teacher of D, then A, B, C can practice on the same broom, D, E can practice on the same broom, in this case, two brooms are needed. If A is B's teacher, B is C's teacher, C is D's teacher, and D is E's teacher, then only one broom is needed. The minimum number of brooms is required.
Suppose there are several pilots, {A1, A2, a3... AK}, {B1, B2, B3 ,... bm }...... {F1, F2, F3 ..... fn }}. It has been sorted in descending order by level, with the same level of pilots in the same set. If the maximum number of brooms is required, only {A1, B1.... F1}, {A2, B2.... F2}... can be combined to minimize the number of brooms. Therefore, the minimum number of brooms required is the set with the largest number of pilots, that is, the set with the highest number of pilots at the same level. Therefore, map in STL can be used for direct implementation.
Code:
/* Maximum hdu 1800 allocation */# include <iostream> # include <map> using namespace std; int main () {int n; while (scanf ("% d ", & n) = 1) {int I; map <int, int> mp; int max = 0; for (I = 0; I <n; I ++) {int level; scanf ("% d", & level); mp [level] ++; if (mp [level]> max) {max = mp [level] ;}} printf ("% d \ n", max) ;}return 0 ;}
Dictionary tree:
#include <iostream>#include<malloc.h>#include<string.h>using namespace std;typedef struct node{int count;node* next[10];}trie;trie* root;char s[35];int maxx;trie* New(){trie* p;p=(trie *)malloc(sizeof(trie));for(int i=0;i<10;i++){p->next[i]=NULL;//p->next[i]->count =0;}p->count=0;return p;}void Insert(char *s){trie* p=root;int len=strlen(s);int j=0;while(s[j]=='0'){j++;}for(int i=j;i<len;i++){int x=s[i]-'0';if(p->next[x]==NULL){p->next[x]=New();}p=p->next[x];}p->count ++;if(p->count >maxx)maxx=p->count ; }int main(){int n;while(scanf("%d",&n)!=EOF){maxx=0;root=New();for(int i=0;i<n;i++){scanf("%s",s);Insert(s);}printf("%d\n",maxx);}return 0;}
This .... Use C ++ to submit...
/*ÌâÒ⣺ÊäÈëÒ»¸öÕûÊýn£¬ÏÂÃæÊäÈënÐвâÊÔÊý¾Ý£¬Ã¿ÐÐÊÇÒ»¸öÕûÊý£¨Ö»º¬Êý×ÖµÄ×Ö·û´££¬Êä³öÏàͬÕûÊýµÄ×î¶à´ÎÊý01,001,0001ÊôÓÚÏàͬµÄÕûÊý */#include<stdio.h>#include<stdlib.h>#include<string.h>//using namespace std;int max;char s[50];typedef struct node{int count;struct node *next[10];}tree;tree *head;void init(){int i;head=(tree *)malloc(sizeof(tree));head->count=0;for(i=0; i<10; i++){head->next[i]=NULL;}}int insert(char *s){tree *q,*p;p=head;int i,j;int len=strlen(s);int k=0; while(s[k]=='0') k++;for(i=k; i<len; i++){if(p->next[s[i]-'0']==NULL){q=(tree*)malloc(sizeof(tree));p->next[s[i]-'0']=q;p=p->next[s[i]-'0'];p->count=0;for(j=0; j<10; j++){p->next[j]=NULL;}}else{p=p->next[s[i]-'0'];}}p->count++;if(p->count>max){max=p->count;}return max;}int main(){int n,i,j;while(scanf("%d",&n)!=EOF){ init(); int num=0; int maxn=0; max=0;for(i=0;i<n;i++){scanf("%s",s);num=insert(s);if(num>maxn){maxn=num;}}printf("%d\n",num);}return 0;}