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();
}
标签:tmp,cnt,last,int,Tree,cin,---,include,Minimal 来源: https://blog.csdn.net/qq_51282224/article/details/122851831