hdu3833YY's new problem

来源:互联网 发布:nginx 域名访问不了 编辑:程序博客网 时间:2024/05/22 05:07

这个题又是想难了,联想到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[i1], P[i2], P[i3] that
P[i1]-P[i2]=P[i2]-P[i3], 1<=i1<i2<i3<=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 i1, i2, i3 can be found, else 'N'.
 

Sample Input
231 3 243 2 4 1
 

Sample Output
NY
 
#include <iostream>#include<cstdio>#include<cstring>//#include<algorithm>#define mm 10003using 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;}


0 0
原创粉丝点击