码迷,mamicode.com
首页 > 其他好文 > 详细

HNU Judging Troubles (字典树)

时间:2015-08-02 21:42:02      阅读:167      评论:0      收藏:0      [点我收藏+]

标签:算法   字典树   

Judging Troubles
Time Limit: 5000ms, Special Time Limit:12500ms, Memory Limit:65536KB
Total submit users: 85, Accepted users: 63
Problem 13352 : No special judgement
Problem description

技术分享
The NWERC organisers have decided that they want to improve the automatic grading of the submissions for the contest, so they now use two systems: DOMjudge and Kattis. Each submission is judged by both systems and the grading results are compared to make sure that the systems agree. However, something went wrong in setting up the connection between the systems, and now the jury only knows all results of both systems, but not which result belongs to which submission! You are therefore asked to help them figure out how many results could have been consistent.


Input

The input consists of:

? one line with one integer n (1 ≤ n ≤ 10^5), the number of submissions;

? n lines, each with a result of the judging by DOMjudge, in arbitrary order;

? n lines, each with a result of the judging by Kattis, in arbitrary order.

Each result is a string of length between 5 and 15 characters (inclusive) consisting of lowercase letters.


Output

Output one line with the maximum number of judging results that could have been the same for both systems.


Sample Input
5
correct
wronganswer
correct
correct
timelimit
wronganswer
correct
timelimit
correct
timelimit
Sample Output
4
Problem Source
NWERC 2014
#include<stdio.h>
struct node{
    node* nxt[26];
    int k;
    node(){
        for(int i=0; i<26; i++)
            nxt[i]=NULL;
        k=0;
    }
};
node* root;
void inset(char s[])
{
    node* p=root;
    int i=0;
    while(s[i]!='\0'){
        if(p->nxt[s[i]-'a']==NULL)
            p->nxt[s[i]-'a']=new node();
        p=p->nxt[s[i]-'a'];
        i++;
    }
    (p->k)++;
}
int query(char s[])
{
    node* p=root;
    int i=0;
    while(s[i]!='\0'&&p->nxt[s[i]-'a']!=NULL){
        p=p->nxt[s[i]-'a'];
        i++;
    }
    if(p->k&&s[i]=='\0')
    {
        (p->k)--; return 1;
    }
    return 0;
}
int main()
{
    int n;
    char s[20];
    while(scanf("%d",&n)>0)
    {
        root=new node();
        for(int i=0; i<n; i++)
        {
            scanf("%s",s);
            inset(s);
        }
        int ans=0;
        while(n--)
        {
            scanf("%s",s);
            ans+=query(s);
        }
        printf("%d\n",ans);
    }
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

HNU Judging Troubles (字典树)

标签:算法   字典树   

原文地址:http://blog.csdn.net/u010372095/article/details/47210499

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!