【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 ...
随机推荐
- 转:maven国内镜像(maven下载慢的解决方法)
http://www.cnblogs.com/xiongxx/p/6057558.html https://jingyan.baidu.com/article/1876c8524ee0d0890a13 ...
- 100个linux系统常用指令
1.ls [选项] [目录名 | 列出相关目录下的所有目录和文件 -a 列出包括.a开头的隐藏文件的所有文件-A 通-a,但不列出"."和".."-l 列出文件 ...
- python内置函数-排列组合函数
product 笛卡尔积 (有放回抽样排列) permutations 排列 (不放回抽样排列) combinations 组合,没有重复 (不放回抽样组合) combinations_with_re ...
- HDU 6228 tree 简单思维树dp
一.前言 前两天沈阳重现,经过队友提点,得到3题的成绩,但是看到这题下意识觉得题目错了,最后发现实际上是题目读错了....GG 感觉自己前所未有的愚蠢了....不过题目读对了也是一道思维题,但是很好理 ...
- 笔记-python-standard library-12.1 pickle
笔记-python-standard library-12.1 pickle 1. pickle简介 source code: Lib/pickle.py pickle模块实质上是一个实现p ...
- python单元测试用例
demo1.py #!/usr/bin/python # encoding: utf-8 def hello(): print "i am in demo1" def add(x, ...
- OpenCV学习笔记(二) cv::Mat
部分内容转自:OpenCV Tuturial,ggicci 在OpenCV Tuturial中可查看Mat的初始化与打印方法. Mat本质上是由两个数据部分组成的类: 矩阵头(包含矩阵尺寸,存储方法, ...
- Beamer模板
普通模板: \documentclass[UTF-8]{beamer} \usepackage{ctex} \usetheme{CambridgeUS} \begin{document} \secti ...
- IntelliJ IDEA下maven Spring MVC配置
1. 导入工程:或者新建Spring web工程,可以参考博客中的Eclipse Spring MVC的方式: 2.配置Tomcat服务器,有两种方式:一是配置maven插件,而是配置本地Tomcat ...
- Spring七大模块
七大模块,如下: 1. Spring Core: Core封装包是框架的最基础部分,提供IOC和依赖注入特性.这里的基础概念是BeanFactory,它提供对Factory模式的经典实现来消除对程序性 ...