hdu 5532
input
1<=T<=2000
2<=n<=10e5
a1 a2 ... an 1<=ai<=10e5
最多二十个n>1000
output
能否从数组中移除一个数使数组变为升序或降序,能输出YES,不能输出NO
做法,用后一个数减前一个数,统计正数的个数和负数的个数,如果全部为正或全部为负肯定可以,一个正或者一个负可能可以,如果这个和前一个或者后一个相加能变成全部正或全部负便可以,因为x1=a[i]-a[i-1],x2=a[i+1]-a[i],则a[i+1]-a[i-1]=x1+x2
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include <cstdio> 2 #include <queue> 3 #include <cstring> 4 #include <iostream> 5 #include <cstdlib> 6 #include <algorithm> 7 #include <vector> 8 #include <map> 9 #include <set> 10 #include <ctime> 11 12 using namespace std; 13 14 int T,n,a,d[100010]; 15 int main() 16 { 17 // freopen("/home/user/桌面/in","r",stdin); 18 scanf("%d",&T); 19 while(T--) 20 { 21 int les=0,gre=0,i,t,fa=-1,fb=-1; 22 scanf("%d%d",&n,&a); 23 for(i=0;i<n-1;i++) 24 { 25 scanf("%d",&t); 26 d[i]=t-a; 27 if(fa==-1&&d[i]<0) fa=i; 28 if(fb==-1&&d[i]>0) fb=i; 29 if(d[i]==0) 30 { 31 les++; 32 gre++; 33 } 34 else d[i]>0?gre++:les++; 35 a=t; 36 } 37 //for(int i=0;i<n-1;i++) printf("%d ",d[i]);printf("\n"); 38 if(gre==n-1||les==n-1) 39 { 40 puts("YES"); 41 continue; 42 } 43 if(gre==n-2) 44 { 45 if(fa==0||fa==n-2||d[fa]+d[fa-1]>=0) 46 { 47 puts("YES"); 48 continue; 49 } 50 else if(fa<n-2&&d[fa]+d[fa+1]>=0) 51 { 52 puts("YES"); 53 continue; 54 } 55 } 56 if(les==n-2) 57 { 58 if(fb==0||fb==n-2||d[fb]+d[fb-1]<=0) 59 { 60 puts("YES"); 61 continue; 62 } 63 else if(fb<n-2&&d[fb]+d[fb+1]<=0) 64 { 65 puts("YES"); 66 continue; 67 } 68 } 69 puts("NO"); 70 } 71 //printf("time=%.3lf",(double)clock()/CLOCKS_PER_SEC); 72 return 0; 73 }