【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 ...
随机推荐
- SunmmerVocation_Learning--Java数组的创建
一维数组声明方式: type var[] 或 type[] var; 如int a[], int[] a; Java中声明数组不能指定其长度,如int a[5]是非法的. 一维数组对象的创建: Jav ...
- Ansible指令和常用模块使用
这里文章记录一下ansible的指令选项和常用的模块使用 ansible指令选项 -m:要执行的模块,默认为command -a:模块的参数 -u:ssh连接的用户名,默认用root,ansible. ...
- 使用U盘给笔记本重做系统
**一.戴尔 Vostro 14 3000 Series **1. 开机时快速按F12进入BIOS界面 **2. 按照下图进行一系列的处理,把U盘被设置为第一启动项 **3. 插入U盘后进入老毛桃PE ...
- Linux档案与文件系统的压缩与打包
总结: 压缩指令为透过一些运算方法去将原本的档案进行压缩,以减少档案所占用的磁盘容量.压缩前与压缩后的档案所占用的磁盘容量比值,就可以被称为是“压缩比” 压缩的好处是可以减少磁盘容量的浪费,在www网 ...
- synchronized同步方法和同步代码块的区别
同步方法默认使用this或者当前类做为锁. 同步代码块可以选择以什么来加锁,比同步方法更精确,我们可以选择只有会在同步发生同步问题的代码加锁,而并不是整个方法. 同步方法使用synchronized修 ...
- JS的跨域理解
前言 周一的学院点开题被批的很惨,换了个校长,各种被抓严,班上已经有两个同学打算休学了.哎,这周的聚会可能是大家集聚的最后一次吧.熬着吧,还是学习我的前端,不管老板学校咋逼了,找个好工作才是王道.今天 ...
- Git之2分钟教程
Git之2分钟入门 普通人:“借我1000块钱”.程序猿:“借你1024吧,凑个整”. 今天是1024,是我们程序员的节日,在此,首先祝各位程序猿以及程序媛们节日快乐~然后送出一份节日礼物,没错,就是 ...
- Leetcode 493.翻转对
翻转对 给定一个数组 nums ,如果 i < j 且 nums[i] > 2*nums[j] 我们就将 (i, j) 称作一个重要翻转对. 你需要返回给定数组中的重要翻转对的数量. 示例 ...
- 菜鸟之路——机器学习之非线性回归个人理解及python实现
关键词: 梯度下降:就是让数据顺着梯度最大的方向,也就是函数导数最大的放下下降,使其快速的接近结果. Cost函数等公式太长,不在这打了.网上多得是. 这个非线性回归说白了就是缩小版的神经网络. py ...
- "R6002 floating point support not loaded"错误
R6002 floating point support not loaded 错误,在Debug模式下会弹出如下错误: "floating point support not loaded ...