cf D. Minimal Height Tree
程序员文章站
2022-08-29 13:27:30
题目题目链接:http://codeforces.com/contest/1437/problem/D思路连续上升的a[i]a[i]a[i]放到同一根节点下代码#include#include#include#include#include#include#include#include...
题目
题目链接:http://codeforces.com/contest/1437/problem/D
思路
连续上升的 a [ i ] a[i] a[i]放到同一根节点下
代码
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<cctype>
#include<ctime>
#include<iostream>
#include<string>
#include<map>
#include<queue>
#include<stack>
#include<set>
#include<vector>
#include<iomanip>
#include<list>
#include<bitset>
#include<sstream>
#include<fstream>
#include<complex>
#include<algorithm>
#if __cplusplus >= 201103L
#include <unordered_map>
#include <unordered_set>
#endif
#define ll long long
using namespace std;
const int INF = 0x3f3f3f3f;
int a[200010];
int main(){
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int t;
cin>>t;
while(t--){
int n;
cin>>n;
for(int i=1;i<=n;i++) cin>>a[i];
map<int,int> mp;
int ans=1;
mp[0]=1;
for(int i=2;i<=n;i++){
if(a[i]<a[i-1]){
mp[ans-1]--;
}
if(mp[ans-1]==0) ans++;//深度++
mp[ans]++;//子树++
}
cout<<ans<<endl;
}
return 0;
}
本文地址:https://blog.csdn.net/kosf_/article/details/109348860
下一篇: Android开发之基本组件的使用