Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

Re:没过的难兄难弟们!测测这终极数据。。。

Posted by fuyuhin at 2014-03-26 18:04:32 on Problem 1363
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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator