HihoCoder-1523(思维)
来源:互联网 发布:mac上的sfc模拟器 编辑:程序博客网 时间:2024/06/06 03:43
Q - 数组重排2 HihoCoder - 1523
给定一个1-N的排列A1, A2, ... AN,每次操作小Hi可以选择一个数,把它放到数组的最左边。
请计算小Hi最少进行几次操作就能使得新数组是递增排列的。
第一行包含一个整数N。
第二行包含N个两两不同整数A1, A2, ... AN。(1 <= Ai <= N)
对于60%的数据 1 <= N <= 20
对于100%的数据 1 <= N <= 100000
一个整数代表答案
52 3 1 4 5
1
这题也是放了有点久是一道思维的题目
在想从后面往前面走 找连续的最长下降子序列到哪里断掉了就是那个i了 嗯 去尝试了一下 真的就A了 其实也是有点参考网上的代码觉得不用那么麻烦
比如
9
3 4 5 7 8 9 6 1 2
这样子根据9来说有7 8 9 而6在7的后面 所以 输出6 有六个要重新排
#include <stdio.h>#include <string.h>#include <stack>#include <algorithm>using namespace std;int pos[100005],digit[100005];int main(){int n;scanf("%d",&n);for(int i=1;i<=n;i++){scanf("%d",&digit[i]);pos[digit[i]]=i;}for(int i=n-1;i>=1;i--){ if(pos[i]>pos[i+1]) { printf("%d\n",i); break; }} return 0;}
阅读全文
0 0
- HihoCoder-1523(思维)
- hihocoder 1523 数组重排2 思维
- hihoCoder #1284 : 机会渺茫(思维,数学)
- hihocoder 1284 机会渺茫(GCD+思维)
- hihocoder#1642 : 三角形面积和(思维)
- (简单思维)HihoCoder
- hihoCoder 1186 : Coordinates(快速求因子【思维】)
- hihocoder#1349 : Nature Numbers(思维)
- hihocoder#1529 : 不上升序列&&Codeforces-713C:Sonya and Problem Wihtout a Legend(思维)
- 2017北京网络赛 hihocoder 1580 Matrix (dp很好的思维题)
- hihocoder week 86 Spring Outing【思维】
- hihocoder 1509 异或排序 二进制思维
- hihocoder 1326 dp OR 思维+枚举
- Hihocoder 1580 Matrix【思维+Dp+RMQ】
- Hihocoder 1632 : Secret Poems 思维|技巧
- hihocoder-1523
- hihocoder 1305 区间求差 经典思维+技巧
- hihoCoder挑战赛12 顺子(hihocoder 1177)
- Leetcode: 654. Maximum Binary Tree
- 特斯拉 CEO 马斯克:年轻人成功的秘诀,只有这 5 点
- 23. 中断配置_dws_dts
- Java学习笔记之IO(五):BufferedOutputStream缓冲输出字节流
- 解决codeblocks找不到iostream.h
- HihoCoder-1523(思维)
- svn 主干and分支
- < 笔记 > JavaScript
- NS-3学习笔记 5
- 静态导入和增强for循环
- git常用命令
- 去除字符串首尾的空白(trim());去除字符串中所有的空白内容(.replaceAll("\\s","")的使用方法
- 24. pin脚控制配置_dts
- jQuery学习笔记—jQuery对象和dom对象相互转化