This problem feels good, before the dictionary tree written is the most comfortable, this several times the game hangs in the dictionary tree also has the shadow AH ~ ~
Main topic:
Give some strings, the query for each string, if there is no return OK, if there is a new string generated, the format of the original string + number, the number of occurrences of the string first several times.
Problem Solving Ideas:
A dictionary tree that counts the number of inserts for each string.
Here's the code:
#include <set> #include <map> #include <queue> #include <math.h> #include <vector># Include <string> #include <stdio.h> #include <string.h> #include <stdlib.h> #include < iostream> #include <cctype> #include <algorithm> #define EPS 1e-10#define pi acos ( -1.0) #define INF 107374182#define INF64 1152921504606846976#define LC l,m,tr<<1#define RC m + 1,r,tr<<1|1#define Zero (a) fabs (a) <eps#define iabs (x) ((x) > 0? (x):-(x)) #define CLEAR1 (A, X, SIZE) memset (A, X, sizeof (a[0]) * (min (size,sizeof (a))) #define ClearAll (A, X) memset (A, X , sizeof (a)) #define MEMCOPY1 (A, X, SIZE) memcpy (A, X, sizeof (X[0)) * (size)) #define Memcopyall (A, X) memcpy (A, X, sizeof ( x) #define MAX (x, Y) (((x) > (y))? (x): (y)) #define min (x, y) (((x) < (y))? (x): (y)) using namespace std;struct node{int p; int num[26];} Node[500000];char s[50];int cnt,len;int insertstring (int strp,int p) {if (Strp==len) {node[p].p++; return NODE[P].P; } if (node[p].num[s[strp]-' a ']==0) {node[p].num[s[strp]-' a ']=cnt++; } return Insertstring (strp+1,node[p].num[s[strp]-' a ');} int main () {int n,temp; Cnt=1; ClearAll (node,0); scanf ("%d", &n); for (int i=0;i<n;i++) {scanf ("%s", s); Len=strlen (s); Temp=insertstring (0,0); if (temp==1) {puts ("OK"); } else printf ("%s%d\n", s,temp-1); } return 0;}
Codeforces Beta Round #4 (Div. 2 only) C. Registration system