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

O(N)扫描算法,贴代码。。。

Posted by yingyuewuhen at 2013-08-30 15:26:37 on Problem 3183
#include <iostream>

using namespace std;

int main()
{
	int n = 0;
	int a[50005];
	int tem = 0;
	int pre;
	while(cin>>n)
	{
		for (int i = 1; i <= n; i++)
		{
			a[i] = i;
		}

		cin>>tem;
		pre = tem;
	
		for (int i = 2; i <= n; i++)
		{
			cin>>tem;
			if(pre < tem && a[i-1] == i-1)
			{
				a[i-1] = i;
				pre = tem;

			}
			else if(pre > tem)
			{
				a[i] = i-1;
				pre = tem;
			}
			else
			{
				pre = tem;
			}
		}
		for (int i = 1; i <= n; i++)
		{
			if(a[i] == i)
				cout<<i<<endl;
		}
	}
	system("pause");
}

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