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 |
帮忙看看我的构造哪里不对while (scanf("%d", &n), n) { memset(flag, 0, sizeof(flag)); for (i = 1; i <= n; i++) { scanf("%d", &a[i]); flag[a[i]] = 1; } for (i = 1; i <= n; i++) if (!flag[i]) { printf("No solution\n"); break; } if (i <= n) continue; top = 0; for (i = 1; i <= n; i++) for (j = i; j <= n; j++) if (a[j] == i) { for (k = j; k > i; k--) { s[top++] = k-1; a[k] = a[k-1]; } a[i] = i; break; } printf("%d", top); while (top) { printf(" %d", s[--top]); } printf("\n"); } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator