码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2014-08-06 11:41:31      阅读:312      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   http   color   os   io   strong   

 
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
 
 1 #include<cstdio>
 2 #include<string.h>
 3 using namespace std;
 4 int hush[10005];
 5 int str[10005];
 6 int main()
 7 {
 8     int t,n;
 9     while(scanf("%d",&t)!=EOF)
10     {
11         while(t--)
12         {
13             scanf("%d",&n);
14             for(int i=1; i<=n; i++)
15             {
16                 scanf("%d",&str[i]);//把1——N保存到数组里
17                 hush[str[i]]=i;//记录每个数的位置
18             }
19             int flag=0;
20             for(int i=1; i<=n; i++)
21             {
22                  for(int j=i+1; j<=n; j++)
23                 {
24                    int temp=str[i]+str[j];//相加
25                    if(temp%2)//优化,必须是偶数才行,尽量别写成temp%2==1,直接写temp%2
26                      continue;
27                    if(hush[temp/2]>i&&hush[temp/2]<j)
28                    {
29                        flag=1;
30                        break;
31                    }
32                 }
33                 if(flag==1) break;
34             }
35             printf("%c",flag==1?Y:N);
36             printf("\n");
37         }
38     }
39     return 0;
40 }

 

 

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

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

标签:des   style   blog   http   color   os   io   strong   

原文地址:http://www.cnblogs.com/angledamon/p/3894128.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!