ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1880. Psych Up's Eigenvalues

Why WA on test 32?
Posted by ChihPih 6 Dec 2011 15:27
Please! Give me 32 test
Re: Why WA on test 32?
Posted by r1d1 6 Dec 2011 17:10
give program
Re: Why WA on test 32?
Posted by ChihPih 6 Dec 2011 18:03
#include <stdio.h>
#include <stdlib.h>

static int b_search(unsigned int array[], int n, int x);

int main()
{
    int i, k, nc;
    char u2f, u3f;
    unsigned int t;
    unsigned short n[3];
    unsigned int u[3][4000];

    for (i = 0; i < 3; i++){
        scanf("%u", &(n[i]));
        for (k = 0; k < n[i]; k++){
            scanf("%u", &t);
            u[i][k] = t;
        }
    }

    nc = 0;
    for (i = 0; i < n[0]; i++){
        u2f = u3f = 0;
        if (i > n[1] || i > n[2]) break;

        u2f = b_search(u[1], n[1], u[0][i]) > -1;
        u3f = b_search(u[2], n[2], u[0][i]) > -1;

        if (u2f && u3f) nc++;
    }
    printf("%d\n", nc);

    return 0;
}

static int b_search(unsigned int array[], int n, int x)
{
    int s, e, m;
    if (n == 0) return -1;

    s = 0; e = n;
    while (s < e){
        m = (s+e)/2;
        if (x <= array[m]) e = m;
        else s = m + 1;
    }

    return array[e] == x ? e : -1;
}

Edited by author 06.12.2011 18:04

Edited by author 06.12.2011 18:20