https://codeforces.com/contest/1490/problem/D
一手递归
终结:没有子树
继续:把最大的找到,为记录,为界,加层数,左范围,右范围

#include<stdio.h>
#include<string.h>
#include<queue>
#define ll long long
#define inf 0x3f3f3f3f
using namespace std;
int a[105];
int b[105];
int n;
void build(int num,int l,int r){if(l>r)return;int i;int max1=l;for(i=l+1;i<=r;i++){if(a[i]>a[max1]){max1=i;}}b[max1]=num;build(num+1,l,max1-1);build(num+1,max1+1,r);
}
int main()
{ int t;scanf("%d",&t);while(t--){scanf("%d",&n);for(int i=1;i<=n;i++){scanf("%d",&a[i]);}memset(b,0,sizeof(b));build(0,0,n);for(int i=1;i<=n;i++){printf("%d ",b[i]);}printf("\n");}return 0;
}

复习代码:
5/18
语法发现:
1.//<bits\stdc++.h>其实是一样的也可以!!
2. //max_element(p,p+n):和sort一样包左不包右;
//注意给的是元素指针,化为整数可以1.*——值2.max_element()-a——序号。注意区分
参考:C++寻找数组最大值和最小值

#include<bits/stdc++.h>//<bits\stdc++.h>其实是一样的也可以!!
#ifdef LOCAL
FILE*FP=freopen("text.in","r",stdin);
#endif
using namespace std;
int a[102],d[102];
void build(int l,int r,int dep){if(l>r)return;int m=max_element(&a[l],&a[r+1])-a;//max_element(p,p+n):和sort一样包左不包右;//注意给的是元素指针,化为整数可以1.*——值2.max_element()-a——序号。注意区分 d[m]=dep;build(l,m-1,dep+1);build(m+1,r,dep+1);
}
signed main(){int t;scanf("%d",&t);while(t--){int n;scanf("%d",&n);for(int i=1;i<=n;i++){scanf("%d",&a[i]);}build(1,n,0);for(int i=1;i<=n;i++){printf("%d",d[i]);putchar((i==n?'\n':' '));}}return 0;
}

(复习次数:1)D - Permutation Transformation——Codeforces Round #702 (Div. 3)相关推荐

  1. Codeforces Round #702 (Div. 3)解题报告

    Codeforces Round #702 (Div. 3) 全部题解 读错题意,写了半天真是心态爆炸,总的来看这次题目不难的. A. Dense Array http://codeforces.co ...

  2. Codeforces Round #702 (Div. 3)A-G题解

    Codeforces Round #702 (Div. 3)A-G题解 比赛链接:https://codeforces.ml/contest/1490 这场F读错题意白给一发,G二分的if(dp[mi ...

  3. Codeforces Round #702 (Div. 3)D. Permutation Transformation

    D. Permutation Transformation 题目 输入样例 3 5 3 5 2 1 4 1 1 4 4 3 1 2 输出样例 1 0 2 3 1 0 0 1 3 2 解题思路 递归,当 ...

  4. Codeforces Round #702 (Div. 3)全部题解

    题目链接:https://codeforces.com/contest/1490 文章目录 A. Dense Array B. Balanced Remainders C. Sum of Cubes ...

  5. Codeforces Round #702 (Div. 3)补题

    题目链接 文章目录 A. Dense Array B. Balanced Remainders C. Sum of Cubes D. Permutation Transformation E. Acc ...

  6. Codeforces Round #702 (Div. 3)

    目录 E. Accidental Victory D. Permutation Transformation G. Old Floppy Drive E. Accidental Victory mai ...

  7. Codeforces Round #702 (Div. 3) A-G

    A. Dense Array 给你 nnn 个数的数组,定义数组有效为任意两个相邻的数 max(arr[i],arr[i−1])/min(arr[i],arr[i−1])<=2max(arr[i ...

  8. Codeforces Round #702 (Div. 3)ABCEF

    A. Плотный массив ограничение по времени на тест2 секунды ограничение по памяти на тест256 мегабайт ...

  9. Codeforces Round #702 (Div. 3)——B

    链接:https://codeforces.com/contest/1490 解析:此题的思路很简单,分别算出C0.C1.C2的值,最终使C0=C1=C2=n/3即可 注意:C0只能+1,即C0转化为 ...

最新文章

  1. tomcat虚拟路径的几种配置方法
  2. Java 之String、StringBuffer 和 StringBuilder 三者区别介绍
  3. MySqli 连接失败 MySQL connection not working: 2002 No such file or directory
  4. Vue HTML:在Vue上写Html遇到的一些问题,html的首行缩进,html的行间距,element UI的回到顶部不显示
  5. file extension php,.php File Extension
  6. dart系列之:元世界pubspec.yaml文件详解
  7. 怎么获取php文件,学习猿地-php怎么获取文件修改时间?
  8. [react] 什么时候使用状态管理器?
  9. json传输二进制的方案【转】
  10. 学生信息系统求助_一个学生信息录入和查询的系统
  11. java使用bks双向认证_android客户端SSL单向双向认证
  12. Redis-慢查询分析
  13. 用递归求字符串的全组合
  14. 2000-2019年中国地级市人均GDP
  15. 使用typescript开发集成阿里云短信接口
  16. 四阶行列式计算_通过考试01 / 行列式的计算
  17. vscode Run coder 支持c++11
  18. 企业wifi认证登录靠谱吗
  19. 微型计算机显卡,“智能”显卡 华硕ROG Matrix显卡赏析
  20. CSS生日快乐:CSS之父Håkon Wium Lie访谈录

热门文章

  1. vue项目中使用ckplayer.js封装视频播放组件
  2. vue中使用html5的drag实现任意位置拖动
  3. 【从零开始数学建模(1)】第一章 建立数学模型~导论
  4. (七)JMockit 的MockUp+@Mock--基础篇
  5. 试用MarkDown标记法和Haroopad编辑器
  6. web自动化验证码处理
  7. 数组转对象 和 对象转数组的简单处理
  8. 孔子的名言,值得一生品读!
  9. 《Non-contact Eye Gaze Tracking System by Mapping of Corneal Reflections》论文阅读
  10. mysql 给表添加唯一约束、联合唯一约束,指定唯一约束的名字