TAG 暴搜 模除
0.2 sec 1232 KB
我不知道第一名那个 0.03 sec 424 KB是怎么办到的。。
注意memset那个不必重置整个数组,重置需要那部分就可以。
/* source code of submission 426449, Zhongshan University Online Judge System */ #include <stdio.h> #include <memory.h> int t,n; int id[300]; bool used[1000000]; int ans; bool check(int x) { memset(used, false, sizeof(bool)*ans ); for (int i=0; i<n; ++i) { int tmp=id[i]%x; if ( used[tmp] ) { return false; } else { used[tmp]=true; } } return true; } int main(int argc, char *argv[]) { scanf("%d", &t); while ( t-- ) { scanf("%d", &n); for (int i=0; i<n; ++i) { scanf("%d", &id[i]); } ans=n; while ( !check(ans) ) { ++ans; } printf("%d/n", ans); } return 0; }
本文介绍了一种使用模除法来寻找一组整数的最小公倍数的方法,并通过一个具体的C语言程序实现该算法。算法首先初始化答案为整数的数量,然后通过检查每个元素对当前答案取模的结果是否唯一,来逐步增加答案的值,直至找到符合条件的最小公倍数值。
9091

被折叠的 条评论
为什么被折叠?



