## Posted By

soulmachine on 03/24/09

# ç»™å®šnä¸ªæ•´æ•°ï¼Œæ±‚ä¸€ä¸ªæœ€å°çš„æ•°ï¼Œä½¿å¾—å®ƒä»¬é™¤ä»¥è¿™ä¸ªæ•°çš„ä½™æ•°ä¸é‡å¤

/ Published in: C

`/** * @brief ç»™å®šnä¸ªæ•´æ•°ï¼Œæ±‚ä¸€ä¸ªæœ€å°çš„æ•°ï¼Œä½¿å¾—å®ƒä»¬é™¤ä»¥è¿™ä¸ªæ•°çš„ä½™æ•°ä¸é‡å¤ * @author soulmachine * @param[in] numbers æ•´æ•°æ•°ç»„ * @param[in] count æ•´æ•°ä¸ªæ•° * @param[in] max_norm æ¨¡çš„æœ€å¤§å€¼ * @return æˆåŠŸè¿”å›žå¤§äºŽ0çš„æœ€å°æ¨¡ï¼Œå¤±è´¥è¿”å›ž0æˆ–-1 * @note æ—  * @remarks æ—  */int decide_norm(int *numbers, int count, int max_norm){    int result = 0;    int *bitmap = NULL; /* å­˜æ”¾ç¬¬ä¸€æ¬¡å‘½ä¸­çš„æ•° */    int norm = 0;     bitmap = (int*)malloc(max_norm * sizeof(int));    if(NULL == bitmap)    {        result = -1;        goto malloc_failed;    }     for(norm = count; norm <= max_norm; ++norm)    {        int i = 0;        memset(bitmap, 0, norm * sizeof(int));        for(i = 0;i < count; i++)        {            int remainder = numbers[i] % norm;            if(0 == bitmap[remainder])            {                bitmap[remainder] = numbers[i];            }            else            {                debug_printf("conflicted: %d %% %d = %d %% %d = %d\n", bitmap[remainder], norm, numbers[i], norm, remainder);                break;            }        }        if(count == i) /* è¿™ä¸ªæ¨¡ä¸‹ï¼Œå„ä¸ªæ•°å€¼æ²¡æœ‰å†²çª */        {            result = norm;            break;        }    } malloc_failed:    return result;}`