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)的啊怎么还110ms

Posted by KatrineYang at 2016-07-30 08:45:22 on Problem 3183 and last updated at 2016-07-30 08:45:44
#include <iostream>
#include <stdio.h>
using namespace std;

int main() {
	int N;
	scanf("%d", &N);
	int q = 0, h;
	int state = 0;//0:正在上升 1:下降
	for(int i = 0; i <= N; i++){
		if(i < N) scanf("%d", &h);
		else h = 0;
		if(state == 0 && h > q){
			q = h;
		}
		else if(state == 0 && h == q){
			printf("%d\n", i);
		}
		else if(state == 0 && h < q){
			state = 1;
			printf("%d\n", i);
			q = h;
		}
		else if(h > q){
			state = 0;
			q = h;
		}
		else if(h == q){
			state = 0;
		}
		else{
			q = h;
		}
	}
	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