Revision: 12694
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at March 24, 2009 23:29 by soulmachine
Initial Code
/** * @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; }
Initial URL
http://www.yanjiuyanjiu.com
Initial Description
/** * @brief 给定n个整数,求一个最å°çš„数,使得它们除以这个数的余数ä¸é‡å¤ * @author soulmachine * @param[in] numbers 整数数组 * @param[in] count 整数个数 * @param[in] max_norm 模的最大值 * @return æˆåŠŸè¿”回大于0的最å°æ¨¡ï¼Œå¤±è´¥è¿”回0或-1 * @note æ— * @remarks æ— */
Initial Title
给定n个整数,求一个最å°çš„数,使得它们除以这个数的余数ä¸é‡å¤
Initial Tags
c
Initial Language
C