| ||||||||||
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 |
Re:没过的难兄难弟们!测测这终极数据。。。In Reply To:没过的难兄难弟们!测测这终极数据。。。 Posted by:wcfairytale at 2007-12-01 17:21:56 > 8 > 7 3 2 5 8 4 6 1 > 1 2 3 4 5 7 8 6 > 0 > > No > Yes > > 过的了这组 应该AC没问题了。。 下面代码能过你那该死的数据!!! 但就是WA #include <stdio.h> #define N 1000 int a[N], stack[N]; int main(int argc, char const *argv[]) { // #ifndef ONLINE_JUDGE // freopen("input.txt", "r", stdin); // #endif int n, p, num, s; while (scanf("%d", &n) != EOF && n != 0) { while (1) { scanf("%d", &a[0]); if (a[0] == 0) { printf("\n"); break; } for (int i = 1; i < n; ++i) { scanf("%d", &a[i]); } num = 1; p = 0; s = 1; stack[0] = -1; // for (int i = 0; i < n; ++i) // { // printf("%d#", a[i]); // } // printf("\n"); while (p < n && num <=n) { // printf("%d %d\n", p, num); if (a[p] == num) { p++; num++; } while (stack[s-1] == a[p]) { s--; p++; } // printf("%d %d\n", s, stack[s-1]); if (a[p] != num && num <= n) { stack[s] = num; num++; s++; } } if (s == 1) { printf("%s\n", "YES"); } else { printf("%s\n", "NO"); } } } getchar(); getchar(); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator