铜牌汇总2
来源:互联网 发布:装修招标网源码 编辑:程序博客网 时间:2024/04/27 18:17
We are all familiar with sorting algorithms: quick sort, merge sort, heap sort, insertion sort, selection sort, bubble sort, etc. But sometimes it is an overkill to use these algorithms for an almost sorted array.
We say an array is sorted if its elements are in non-decreasing order or non-increasing order. We say an array is almost sorted if we can remove exactly one element from it, and the remaining array is sorted. Now you are given an arraya1,a2,…,an a1,a2,…,an, is it almost sorted?
We say an array is sorted if its elements are in non-decreasing order or non-increasing order. We say an array is almost sorted if we can remove exactly one element from it, and the remaining array is sorted. Now you are given an array
There are at most 20 test cases with
332 1 733 2 153 1 4 1 5
YESYESNO
#include<stdio.h>#include<string.h>int stack[100000];int top;int f(int x){ int l=0,r=top; int mid; while(r>=l) { mid=(l+r)/2; if(x>=stack[mid]) l=mid+1; else r=mid-1; } return l;}int main(){ int t,n,m,j,i,k; scanf("%d",&t); while(t--) { scanf("%d",&n); int s[100000]; for(i=1;i<=n;i++) scanf("%d",&s[i]); top=0; stack[0]=-1; for(i=1;i<=n;i++) { if(s[i]>=stack[top]) stack[++top]=s[i]; else stack[f(s[i])]=s[i]; } int ans=top; memset(stack,0,sizeof(0)); top=0; stack[0]=-1; for(i=n;i>=1;i--) { if(s[i]>=stack[top]) stack[++top]=s[i]; else stack[f(s[i])]=s[i]; } int ant=top; if(n-ant<=1||n-ans<=1) printf("YES\n"); else printf("NO\n"); } return 0;}
阅读全文
0 0
- 铜牌汇总2
- 铜牌汇总1
- 2011DLUT现场赛 2道铜牌难度题
- 金牌、银牌、铜牌
- 金牌、银牌、铜牌
- 金牌、银牌、铜牌
- 金牌、银牌、铜牌
- 金牌、银牌、铜牌
- sdut2057金牌、银牌、铜牌
- 金牌、银牌、铜牌
- 金牌 银牌 铜牌
- 链表->金银铜牌
- 金牌、银牌、铜牌
- sdut acm 金银铜牌
- 金牌、银牌、铜牌
- 金牌银票铜牌
- 金牌、银牌、铜牌--链表
- 2057-->金牌,银牌,铜牌
- Robot Framework用法总结
- 安卓查询连接wifi的终端型号功能实现(查看蹭网)
- linux I2C驱动调试日志
- java 常用集合list与Set、Map区别及适用场景总结
- 自定义View系列文章目录
- 铜牌汇总2
- Halcon中缩放Region或XLD的方法研究
- python+appium重写元素定位的方法
- 注解的方式实现redis分布式锁
- 团队天梯赛L1-012. 计算指数
- vue.js之filter过滤器
- Jenkins启动失败之解决
- PAT and CSP 认证
- 实现求链表中的最大整数的递归算法