【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 ...
随机推荐
- Freemaker基于word模板动态导出压缩文件汇总整理
Freemaker基于word模板动态导出压缩文件汇总整理 Freemaker基于word模板动态导出单个文件思路和代码详情见连接: https://www.cnblogs.com/lsy-blogs ...
- 最新手机号正则表达式php包括166等号段
if(!preg_match("/^((13[0-9])|(14[5,7])|(15[0-3,5-9])|(17[0,3,5-8])|(18[0-9])|166|198|199|(147)) ...
- MySQL批量插入大量数据方法
在MySQL数据库中,如果要插入上百万级的记录,用普通的insert into来操作非常不现实,速度慢人力成本高,推荐使用Load Data或存储过程来导入数据,我总结了一些方法分享如下,主要基于My ...
- Vue2.0--14.小白入门教程--实例化多个vue对象,可初始化操作几种方法
课程地址: https://study.163.com/course/courseMain.htm?courseId=1004711010 <!DOCTYPE html> <html ...
- 12、python中的函数(高阶函数)
一.高阶函数 函数实际上也是一个对象,所以也能由变量指向一个函数对象,实际上函数名就是一个变量名.那么函数是传入变量作为参数的,如果传入的变量指向的是函数对象,这种函数就叫高阶函数. 高阶函数就是传入 ...
- 笔记-编程-IO模型
笔记-编程-IO模型 1. 简介 常用IO模型 1) 同步阻塞IO(Blocking IO) 2) 同步非阻塞IO(Non-blocking IO) 3) IO ...
- (ADO.NET小知识点汇总)看到什么记什么
1.数据库连接池:在同时连接数不多的情况下, 打开一个链接往数据库导1W条数据的耗时 跟 导一条数据就打开跟关闭数据库连接的耗时 两者其实相差不大,这是为什么呢?打开关闭的本身不是有很多耗时吗?这是因 ...
- python实现分布式进程
今天用python实现分布式,基于python2.7,注意:在linux下执行测试通过,在windows测试失败.# -*- coding: utf-8 -*-__author__ = 'dell'i ...
- git上传自己的代码
感谢这个哥们的博客,不过里面有些错误. http://www.cnblogs.com/ruofengzhishang/p/3842587.html 下面是我自己的实践成功的: 这篇文章写得是windo ...
- APK无源码使用Robotium简单总结
1.使用re-sign.jar对待测包进行重签名,并记录下包名和主Activity名. 2.在Eclipse中点击File-New-Other 选择Android下的Android Test Proj ...