Tuesday, October 11, 2011

11849 - CD

Based on the given conditions you can have it done with Linear Search. A simpler approach would be to use MAP, give O(nlgn).
#include <stdio.h>
int ar[10000000];
int main()
{
    int i, a, b, counter, val, s, temp, min;
    while (scanf("%d %d",&a,&b)==2)
    {
        if (!a && !b) return 0;
        counter=0;

        for (i=0 ; i<a ; i++)
        {
            scanf("%d",&ar[i]);
        }

        for (i=0, s=0 ; i<b ; i++)
        {
            scanf("%d",&temp);
            for ( ; temp>=ar[s] && s<a ; s++)
            {
                if (ar[s] == temp)
                {
                    counter++;
                    break;
                }
            }
        }
        printf("%d\n",counter);
    }
    return 0;
}

No comments:

Post a Comment

Post your comment here. If you want to say something about programming problems, scripts, software etc, please try to be as descriptive as possible.

Connect Rapoo MT750S with Linux (Tested on Manjaro)

 I bought this obvious copy of MX Master 2S in hopes of having the device switching functionality along with a lightweight body because I ha...