【HDOJ5532】Almost Sorted Array(签到)
题意:给定一个n个数的数列,问删掉一个数之后剩余部分是否可以单调不增或单调不减
n<=1e5,a[i]<=1e5
思路:预处理一下前后缀是否合法
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef vector<int> VI;
#define fi first
#define se second
#define MP make_pair
#define N 210000
#define M 1100
#define MOD 2147493647
#define eps 1e-8
#define pi acos(-1) int a[N],b[N],c[N],k; int main()
{
//freopen("F.in","r",stdin);
//freopen("F.out","w",stdout);
int cas;
scanf("%d",&cas);
for(int v=;v<=cas;v++)
{
k=;
int n;
scanf("%d",&n);
for(int i=;i<=n;i++)
{
scanf("%d",&a[i]);
b[i]=c[i]=;
}
b[]=;
for(int i=;i<=n;i++)
if(b[i-]==&&a[i]>=a[i-]) b[i]=;
else c[i]=;
c[n]=;
for(int i=n-;i>=;i--)
if(c[i+]==&&a[i]<=a[i+]) c[i]=;
else c[i]=;
int flag=;
//for(int i=1;i<=n;i++) printf("%d ",b[i]);
// printf("\n");
//for(int i=1;i<=n;i++) printf("%d ",c[i]);
// printf("\n");
for(int i=;i<=n;i++)
{
if(i>&&b[i-]==) continue;
if(i<n&&c[i+]==) continue;
if(i>&&i<n&&a[i-]>a[i+]) continue;
flag=; k=i;
break;
}
// printf("%d\n",k);
for(int i=;i<=n;i++) b[i]=c[i]=;
b[]=;
for(int i=;i<=n;i++)
if(b[i-]==&&a[i]<=a[i-]) b[i]=;
else break;
c[n]=;
for(int i=n-;i>=;i--)
if(c[i+]==&&a[i]>=a[i+]) c[i]=;
else break;
for(int i=;i<=n;i++)
{
if(i>&&b[i-]==) continue;
if(i<n&&c[i+]==) continue;
if(i>&&i<n&&a[i-]<a[i+]) continue;
flag=; k=i;
break;
}
// printf("%d\n",k);
if(flag) printf("YES\n");
else printf("NO\n");
}
return ;
}
【HDOJ5532】Almost Sorted Array(签到)的更多相关文章
- Merge Sorted Array
Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array. Note:Yo ...
- [LeetCode] Find Minimum in Rotated Sorted Array II 寻找旋转有序数组的最小值之二
Follow up for "Find Minimum in Rotated Sorted Array":What if duplicates are allowed? Would ...
- [LeetCode] Find Minimum in Rotated Sorted Array 寻找旋转有序数组的最小值
Suppose a sorted array is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6 7 migh ...
- [LeetCode] Convert Sorted Array to Binary Search Tree 将有序数组转为二叉搜索树
Given an array where elements are sorted in ascending order, convert it to a height balanced BST. 这道 ...
- [LeetCode] Merge Sorted Array 混合插入有序数组
Given two sorted integer arrays A and B, merge B into A as one sorted array. Note:You may assume tha ...
- [LeetCode] Search in Rotated Sorted Array II 在旋转有序数组中搜索之二
Follow up for "Search in Rotated Sorted Array":What if duplicates are allowed? Would this ...
- [LeetCode] Remove Duplicates from Sorted Array II 有序数组中去除重复项之二
Follow up for "Remove Duplicates":What if duplicates are allowed at most twice? For exampl ...
- [LeetCode] Search in Rotated Sorted Array 在旋转有序数组中搜索
Suppose a sorted array is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6 7 migh ...
- [LeetCode] Remove Duplicates from Sorted Array 有序数组中去除重复项
Given a sorted array, remove the duplicates in place such that each element appear only once and ret ...
- Remove Duplicates from Sorted Array II
题目简述 Follow up for "Remove Duplicates": What if duplicates are allowed at most twice? For ...
随机推荐
- 虚拟主机的搭建(ubuntu+apache2)
搭建环境:windows+VMware(Ubuntu)+apache2.(同一IP,不同域名) 1:在VMware的虚拟机Ubuntu下安装apache2(怎么安装百度一下就能找到): 2: apac ...
- Python学习笔记(二):数据类型
一.python中的数据类型 python中的数据类型包括:整型.浮点型.布尔型.字符串类型 整型(int)和浮点型(float) Python中的整型只有int,没有short.long:浮点型fl ...
- linux下查找文件命令总结
主要有find,locate,whereis,which等 1. find是最常用也是最强大的查找命令,它可以查找任何类型的文件. find命令的一般格式为:find <指定目录>< ...
- Mysql相关子查询&&MySQL获取分组后的TOP N记录
小燕子,哈哈哈哈~~~~~~~~~~ 相关子查询是指引用了外部查询列的子查询,即子查询会对外部查询的每行进行一次计算. 举个例子 root:test> show create table tes ...
- Spring---环境搭建与包介绍
jar包下载路径 首先需要下载Spring框架 spring-framework-5.0.0.RELEASE-dist,官方地址为https://repo.spring.io/release/org/ ...
- optparser 模块 提取IP,端口,用户名,密码参数模板
import optparse #class FtpClient(object): #自定义类可以自己修改 '''ftp客户端''' #def __init__(self): parser = opt ...
- Docker背后的内核知识(二)
cgroups资源限制 上一节中Docker背后的内核知识(一),我们了解了Docker背后使用的资源隔离技术namespace,通过系统调用构建了一个相对隔离的shell环境,也可以称之为简单的“容 ...
- Excel动画教程50例(一)
Excel动画教程50例(一) 1.自动筛选 2.在Excel中字符替换 3.在Excel中冻结行列标题 4.在Excel中为导入外部数据 5.在Excel中行列快速转换 6.共享Excel工作簿 7 ...
- IOS开发学习笔记026-UITableView的使用
UITableView的简单使用过程 简单介绍 两种样式 UITableViewStylePlain UITableViewStyleGrouped 数据显示需要设置数据源,数据源是符合遵守协议 &l ...
- Windows API 学习记录1
这里面的好多函数不能死记硬背,知道有这个函数就行,等用到了,再回来细看 一.窗口管理函数包括以下几类: 按钮函数(Button) Microsoft提供了对话框和控制来支持应用程序与用户之间的交互通讯 ...