hdu 5532 Almost Sorted Array (水题)
Almost Sorted Array
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 8541 Accepted Submission(s): 1982
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 a1,a2,…,an, is it almost sorted?
1≤T≤2000
2≤n≤105
1≤ai≤105
There are at most 20 test cases with n>1000
3
2 1 7
3
3 2 1
5
3 1 4 1 5
YES
NO
#include<cstdio>
#include<cstring>
#include<algorithm> using namespace std; const int maxn=; int a[maxn+]; int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n;
scanf("%d",&n);
for(int i=;i<=n;i++)
scanf("%d",a+i); bool flag1=true,flag2=true; for(int i=,j=;i<=n;i++)
{
if(a[i]<a[i-])
j++;
if(j==)
{
flag1=false;
break;
}
}
if(flag1)
{
for(int i=;i<=n;i++)
{
if(a[i]<a[i-])
{
if(i!=n&&a[i+]<a[i-]&&i-!=&&a[i-]>a[i])
flag1=false;
break;
}
}
} for(int i=,j=;i<=n;i++)
{
if(a[i]>a[i-])
j++;
if(j==)
{
flag2=false;
break;
}
}
if(flag2)
{
for(int i=;i<=n;i++)
{
if(a[i]>a[i-])
{
if(i!=n&&a[i+]>a[i-]&&i-!=&&a[i-]<a[i])
flag2=false;
break;
}
}
} if(flag1||flag2)
printf("YES\n");
else
printf("NO\n");
}
return ;
}
hdu 5532 Almost Sorted Array (水题)的更多相关文章
- hdu 5532 Almost Sorted Array(模拟)
Problem Description We are all familiar with sorting algorithms: quick sort, merge sort, heap sort, ...
- HDU 5532 Almost Sorted Array (最长非递减子序列)
题目链接 Problem Description We are all familiar with sorting algorithms: quick sort, merge sort, heap s ...
- HDU 5532——Almost Sorted Array——————【技巧】
Almost Sorted Array Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Ot ...
- hdu 5532 Almost Sorted Array nlogn 的最长非严格单调子序列
Almost Sorted Array Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Ot ...
- HDU - 5532 Almost Sorted Array (最长非严格单调子序列)
We are all familiar with sorting algorithms: quick sort, merge sort, heap sort, insertion sort, sele ...
- 【HDU 5532 Almost Sorted Array】水题,模拟
给出一个序列(长度>=2),问去掉一个元素后是否能成为单调不降序列或单调不增序列. 对任一序列,先假设其可改造为单调不降序列,若成立则输出YES,不成立再假设其可改造为单调不增序列,若成立则输出 ...
- hdu 5532 Almost Sorted Array
http://acm.hdu.edu.cn/showproblem.php?pid=5532 题目大意: 给你一个不规则的序列,问是否能够通过删除一个元素使其成为一个有序的序列(递增或递减(其中相邻 ...
- CF451B Sort the Array 水题
Codeforces Round #258 (Div. 2) Sort the Array B. Sort the Array time limit per test 1 second memory ...
- HDU 5538 L - House Building 水题
L - House Building Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.ph ...
随机推荐
- 函数式接口的使用 (Function、Predicate、Supplier、Consumer)
参考:https://blog.csdn.net/jmj18756235518/article/details/81490966 函数式接口 定义:有且只有一个抽象方法的接口 Function< ...
- ubuntu 16.04源码编译和配置caffe详细教程 | Install and Configure Caffe on ubuntu 16.04
本文首发于个人博客https://kezunlin.me/post/b90033a9/,欢迎阅读! Install and Configure Caffe on ubuntu 16.04 Series ...
- 扛把子组20191017-5 alpha week 2/2 Scrum立会报告+燃尽图 04
此作业要求参见[https://edu.cnblogs.com/campus/nenu/2019fall/homework/9801] 一.小组情况 队名:扛把子 组长:迟俊文 组员:宋晓丽 梁梦瑶 ...
- Linux root设置初始值的方法
Linux root设置初始值的方法 ubuntu默认不允许使用root登录,因此初始root账户是不能使用的,需要在普通账户下利用sudo权限修改root密码. 在终端输入sudo passwd r ...
- GitHub 标星 1.6w+,我发现了一个宝藏项目,作为编程新手有福了!
大家好,我是 Rocky0429,一个最近老在 GitHub 上闲逛的蒟蒻... 特别惭愧的是,虽然我很早就知道 GitHub,但是学会逛 GitHub 的时间特别晚.当时一方面是因为菜,看着这种全是 ...
- JavaScript---1.计算机的编程基础
学习内容:编程语言.计算机基础 1编程语言 程序员通过编程语言来控制计算机 编程语言:机器语言(计算机只认识机器语言).汇编语言(直接对硬件操作,指令采用英文缩写的标识符,容易记忆).高级语言(C\C ...
- < AlexNet - 论文研读个人笔记 >
Alexnet - 论文研读个人笔记 一.论文架构 摘要: 简要说明了获得成绩.网络架构.技巧特点 1.introduction 领域方向概述 前人模型成绩 本文具体贡献 2.The Dataset ...
- tcp协议传输方法&粘包问题
socket实现客户端和服务端 tcp协议可以用socket模块实现服务端可客户端的交互 # 服务端 import socket #生成一个socket对象 soc = socket.socket(s ...
- Spring Boot整合MyBatis(非注解版)
Spring Boot整合MyBatis(非注解版),开发时采用的时IDEA,JDK1.8 直接上图: 文件夹不存在,创建一个新的路径文件夹 创建完成目录结构如下: 本人第一步习惯先把需要的包结构创建 ...
- SpringBoot打成war包,部署Tomcat服务器
1: 创建spring boot项目 使用 Spring initializr 可以直接选择创建包的方式 也可以选择在Pom中更改 <groupId>com.dgw</grou ...