Poj Solution 3060

http://poj.org/problem?id=3060

#include <stdio.h>
#include <memory.h>

int m[1000][1000];
int sx[1000], sy[1000];
int main() {
    int t, n, i, j, d, a, b, best;
    
    scanf( "%d", &t );
    while( t-- ) {
        scanf( "%d%d", &d, &n );

        best = 99999999;
        memset( m, 0, sizeof m );
        memset( sx, 0, sizeof sx );
        memset( sy, 0, sizeof sy );

        for( i=0; i<n; i++ ) {
            scanf( "%d%d", &a, &b );
            m[(a%d+d)%d][(b%d+d)%d]++;
            sx[(a%d+d)%d]++;
            sy[(b%d+d)%d]++;
        }
        for( i=0; i<d; i++ )
        for( j=0; j<d; j++ )
            if( sx[i] + sy[j] - m[i][j] < best )
                best = sx[i] + sy[j] - m[i][j];
        printf( "%dn", best );
    }
    return 0;
}
											
This entry was posted in poj. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *