2017年百度校招笔试题 士兵队列 百度2017秋招真题

题目描述
									

 

一队士兵在操场上排成一列,士兵总数为n,士兵按照队伍从前往后的顺序从1到n依次编号。每个士兵有各自的身高,第i个士兵的身高为ai。
士兵列队完毕后,将军走到队列的最前面。因为身高不一,有些士兵可能被前面身高更高的挡住了,这样将军就看不到他们。将军能看到某个士兵当且仅当他的身高严格大于他前面的所有士兵。
问将军一共能看到多少个士兵。

 

注意: 这道题目不是最长上升子序列问题,因为将军是从第一个士兵开始看到,比较简单。

#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
const int N = 10000;
int nums[N];
int dp[N];

int main()
{
	int T;
	scanf("%d", &T);
	while (T--) {
		int n;;
		scanf("%d", &n);
		int res = 1, temp = 0;
		scanf("%d", &nums[0]);
		temp = nums[0];
		for (int i = 1; i < n; i++){
			scanf("%d", &nums[i]);
			if (nums[i] > temp) {
				temp = nums[i];
				res++;
			}
		}
		printf("%d\n", res);
	}
}