# YY's new problem

Time Limit: 12000/4000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 3434    Accepted Submission(s): 961

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
2 3 1 3 2 4 3 2 4 1

Sample Output
N Y

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int main (void)
{
int t,n,m,i,j,k,l,s[11111],hash[11111];
scanf("%d",&t);
while(t--&&scanf("%d",&n)!=EOF)
{
memset(hash,0,sizeof(hash));
for(i=0;i<n;i++)
{
scanf("%d",&s[i]);
hash[s[i]]=i;	//记录当前数所在的位子
}
for(i=k=0;!k&&i<n;i++)
{
if(i<n/2)
for(j=0;j<i;j++)	//前半段通过i1,i2找i3
{
l=2*s[i]-s[j];
if(l>0&&l<=n&&hash[l]>i)
{
k=1;break;
}
}else
for(j=n-1;!k&&j>i;j--)	//后半段通过i2,i3找i1
{
l=2*s[i]-s[j];
if(l>0&&l<=n&&hash[l]<i)
{
k=1;break;
}
}
}
if(k)puts("Y");
else puts("N");
}
return 0;
}

• 本文已收录于以下专栏：

举报原因： 您举报文章：HDU--杭电--3833--YY's new problem 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)