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

请教

Posted by wywcgs at 2005-10-30 04:20:30 on Problem 2559
以下代码运行结果为Runtime Error,怀疑是scanf("%lld", &h[i]);没有正确读取h[i]所致,我在本人及其上调试过,确实出现过错误读取,但是由于本人操作系统为Windows所以不敢肯定poj会怎么样。换成cin >> h[i]后变为超时。此代码在zoj上已经ac,还望高人指教错误之处。




#include <cstdio>

const long MAX = 102400;

int main()
{
	long stack[MAX], top;
	long left[MAX], right[MAX];
	long i, n;
	long long h[MAX], max, p;

	while(scanf("%ld", &n) == 1) {
		if(n == 0) {
			return 0;
		} else {
			top = 0;
			stack[top++] = 0;
			h[0] = h[n+1] = -1;
			for(i = 1; i <= n; i++) {
				scanf("%lld", &h[i]);  //  可疑之处
				while(h[stack[top-1]] >= h[i]) {
					top--;
				}
				left[i] = stack[top-1];  //  按理说此行有可能出现RE,但我设定stack[0] = 0,h[0] = -1,而且任何h[i] > 0,所以此行是不会RE的
				stack[top++] = i;
			}
			top = 0;
			stack[top++] = n + 1;
			max = -1;
			for(i = n; i > 0; i--) {
				while(h[stack[top-1]] >= h[i]) {
					top--;
				}
				right[i] = stack[top-1];
				stack[top++] = i;
				p = (right[i] - left[i] - 1) * h[i];
				if(p > max) {
					max = p;
				}
			}
			printf("%lld\n", max);
		}
	}
	
	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