这个题又是想难了,联想到poj2549 看了题解 自己写WA了好多次 ==其实之前犯过这个错误T^T 跳出循环时要注意 题中给的数得读入结束才行 长点心吧。。。
2 3 1 3 2 4 3 2 4 1
N Y
#include <iostream> #include<cstdio> #include<cstring> //#include<algorithm> #define mm 10003 using namespace std; int t,n,s,flag; int hsh[mm]; int main() { // freopen("cin.txt","r",stdin); cin>>t; while(t--) { cin>>n; memset(hsh,0,sizeof(hsh)); flag=0; for(int i=0;i<n;i++) { scanf("%d",&s); hsh[s]=1; if(flag==0) { for(int j=1;j<s&&j+s<=n;j++) { if(hsh[s+j]+hsh[s-j]==1) { flag=1; break; } } } //if(flag) break;//就是这里 如果这么就跳出来了 会有数没读完 } if(flag) cout<<"Y"<<endl; else cout<<"N"<<endl; } return 0; }