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 |
O(N)扫描算法,贴代码。。。#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator