Codeforces Beta Round #4 (Div. 2 Only) C. Registration system_html/css_WEB-ITnose

WBOY
Release: 2016-06-24 11:53:10
Original
1096 people have browsed it

This question feels pretty good. In the past, the dictionary tree was the easiest to write, but in these competitions, it has been shadowed by the dictionary tree~~



The main idea of ​​the question:

Give Output some strings and query each string. If it does not appear, it returns OK. If it does, it generates a new string. The format is the number of the original string, and the number is the number of times this string appears repeatedly.



Solution ideas:

Dictionary tree, counting the number of insertions for each string.



Here is 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;}
Copy after login


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template