D. Minimal Height Tree---思维题

D. Minimal Height Tree---思维题

D. Minimal Height Tree---思维题

#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
#define int long long
const int N = 200010;
void solve()
{
	int n;cin>>n;
	int last;cin>>last;
	int cnt=0,tmp=0,res=0;
	for(int i=2;i<=n;i++)
	{
		int x;cin>>x;
		if(last>x)
		{
			if(cnt)cnt--,tmp++;
			else res++,cnt=tmp-1,tmp=1;
		}
		else tmp++;
		last=x;
	}
	cout<<res+1<<endl;
}
signed main()
{
    int T;
    cin>>T;
    while(T--)solve();
}
上一篇:md5、sha1弱比较,md5($pass,true)总结


下一篇:SpringBoot定制SpringMV