标签:
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 430 Accepted Submission(s): 196
#include<iostream> #include<cstdio> using namespace std; #define maxn 100005 #define INF 0x3f3f3f3f int a[maxn], n; bool stobig() // 判断该数组变成 非递减数组是否只需要删除一个数 { int sum = 0; a[0] = -INF, a[n+1] = INF; for(int i = 1; i <= n; i++) { if(a[i-1] > a[i]) { if(sum == 1) return false; sum++; if( a[i-1] > a[i+1] && a[i] < a[i-2] ) return false; } } return true; } bool btosmall() // 判断该数组变成 非递增数组是否只需要删除一个数 { int sum = 0; a[0] = INF, a[n+1] = -INF; for(int i = 1; i <= n; i++) { if(a[i] < a[i+1]) { if(sum == 1) return false; sum++; if( a[i-1] < a[i+1] && a[i+2] > a[i] ) return false; } } return true; } int main() { int t; scanf("%d", &t); while(t--) { scanf("%d", &n); for(int i = 1; i <= n; i++) { scanf("%d", &a[i]); } if(stobig() || btosmall()) printf("YES\n"); else printf("NO\n"); } return 0; }
标签:
原文地址:http://www.cnblogs.com/Tinamei/p/4937081.html