Test instructions: It means that there are several pilots that need to practice flying on a broom, each with a different grade, and a high-level pilot who can be the teacher of a low-level pilot, and each pilot has at most and only one teacher and student. Pilots with teacher-student relationships can practice on the same broom, and this nature is transitive. That is, for example have a,b,c,d,e five pilots, and grade is a>b>c>d>e, then can make a when B's teacher, b when C's teacher, E when D's teacher, then a,b,c can practice on the same broom, d,e on the same broom practice, so need 2 broom , and if is a teacher of B, b when the teacher of C, c when the teacher of D, D when the teacher of E, then only need a broom. The number of brooms required for the topic is the minimum.
#include <iostream> #include <cstdio> #include <cstring> #include <cstdlib> #include < cmath> #include <vector> #include <queue> #include <stack> #include <map> #include < algorithm> #include <set>using namespaceStd;typedefLong Longll;typedefunsigned long longUll;#define MM (A, B) memset (A,b,sizeof (a));ConstDoubleEps =1e-10;ConstintInf =0x7f7f7f7f;ConstDoublePi=ACOs(-1);ConstintMaxn= -+ +;CharS[ Max];intHash[4000];intBkdrhash(Char*S){Long LongSeed=131;Long LongHashv=0; while(*S==' 0 ')S++; while(*S) {Hashv=Hashv*Seed+(*S++); }return (Hashv&0x7FFFFFFF);}intMain(){intN; while(~scanf("%d",&N)) { for(intI=1;I<=N;I++) {scanf('%s ',S);Hash[I]=Bkdrhash(S); }Sort(Hash+1,Hash+N+1);intAns=1,Tmp=1; for(intI=2;I<=N;I++) {if(Hash[I]==Hash[I-1])Tmp++;ElseTmp=1;Ans=Max(Ans,Tmp); }Printf("%d\n",Ans); }return0;}
Analysis: Just find out the number of occurrences of the most repeated occurrences
HDU 1800 string Hash bare topic