Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
为什么要这样大牛的AC代码 #include <cstdio> #include <cstring> #include <algorithm> using std::sort; const int maxn = 105; bool isp[maxn]; int p[maxn], lp; void make() { memset(isp, true, sizeof(isp)); lp = 0; for (int i = 2; i < maxn; ++i) if (isp[i]) { p[lp++] = i; for (int j = i * i; j < maxn; j += i) isp[j] = false; } } int step[maxn], maxm, cycle[maxn], lc; void dfs(int remain, int k) { if (p[k] > remain) { int m = 1; for (int i = 0; i < k; ++i) if (step[i]) m *= step[i]; if (m > maxm) { maxm = m; lc = 0; for (int i = 0; i < k; ++i) if (step[i]) cycle[lc++] = step[i]; while (remain--) cycle[lc++] = 1; } } else { step[k] = 0; dfs(remain, k + 1); for (step[k] = p[k]; step[k] <= remain; step[k] *= p[k]) dfs(remain - step[k], k + 1); } } int main() { make(); int T, n; scanf("%d", &T); while (T--) { scanf("%d", &n); maxm = 1, lc = 0; if (n == 1) cycle[lc++] = 1; else dfs(n, 0); sort(cycle, cycle + lc); printf("%d", maxm); int k = 1, tmp; for (int i = 0; i < lc; ++i) { tmp = k++; for (int j = 1; j <= cycle[i] - 1; ++j) printf(" %d", k++); printf(" %d", tmp); } printf("\n"); } return 0; } 我把for (step[k] = p[k]; step[k] <= remain; step[k] *= p[k]) dfs(remain - step[k], k + 1); 改为 int j=1; for (step[k] = p[k],j = 1; j * step[k] <= remain; j ++ ) dfs(remain - j * step[k], k + 1); 为什么WA了 我觉得是他的错了,我的对了啊。郁闷…… Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator