G - YY's new problem(HUSH算法,目前还不懂什么是HUSH算法)

时间:2023-03-09 09:29:19
G - YY's new problem(HUSH算法,目前还不懂什么是HUSH算法)

Time Limit:4000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u

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<cstdio>
#include<string.h>
using namespace std;
int hush[];
int str[];
int main()
{
int t,n;
while(scanf("%d",&t)!=EOF)
{
while(t--)
{
scanf("%d",&n);
for(int i=; i<=n; i++)
{
scanf("%d",&str[i]);//把1——N保存到数组里
hush[str[i]]=i;//记录每个数的位置
}
int flag=;
for(int i=; i<=n; i++)
{
for(int j=i+; j<=n; j++)
{
int temp=str[i]+str[j];//相加
if(temp%)//优化,必须是偶数才行,尽量别写成temp%2==1,直接写temp%2
continue;
if(hush[temp/]>i&&hush[temp/]<j)
{
flag=;
break;
}
}
if(flag==) break;
}
printf("%c",flag==?'Y':'N');
printf("\n");
}
}
return ;
}