hdu3833YY's new problem

这个题又是想难了,联想到poj2549 看了题解 自己写WA了好多次 ==其实之前犯过这个错误T^T 跳出循环时要注意 题中给的数得读入结束才行 长点心吧。。。

Problem Description
Given a permutation P of 1 to N, YY wants to know whether there exists such three elements P[i 1], P[i 2], P[i 3] that
P[i 1]-P[i 2]=P[i 2]-P[i 3], 1<=i 1<i 2<i 3<=N.
 

Input
The first line is T(T<=60), representing the total test cases.
Each test case comes two lines, the former one is N, 3<=N<=10000, the latter is a permutation of 1 to N.
 

Output
For each test case, just output 'Y' if such i 1, i 2, i 3 can be found, else 'N'.
 

Sample Input
   
   
   
   
2 3 1 3 2 4 3 2 4 1
 

Sample Output
   
   
   
   
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;
}


你可能感兴趣的:(hdu3833YY's new problem)