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.
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.
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
- hdu3833YY's new problem
- HDU3833:YY's new problem
- HDU YY's new problem
- HDU/HDOJ 3833 YY's new problem
- HDOJ 3833 YY's new problem
- hdu 3833 YY's new problem
- 暴力搜索_HDU3833_YY's new problem
- HDU-3833 YY's new problem
- POJ 3833 YY's new problem
- hdu 3833 YY's new problem
- hdu 3833 YY's new problem
- HDU 3833 YY's new problem 哈希
- hdu3833 YY's new problem--哈希表
- hdu 【3833】YY's new problem
- hdu 3833 YY's new problem
- HDU 3833 YY's new problem ()
- 哈希算法---YY's new problem
- Hdu3833 YY's new problem 哈希表(3)
- 递归
- 【番外篇】关于对冲的一点想法
- POJ 1703
- Java 构造器(定义,作用,原理)
- Uva - 11134 - Fabled Rooks
- hdu3833YY's new problem
- javascript call和apply
- java学习第一阶段4
- Tomcat中HttpServletResponse的实现类
- PHP实现同一个帐号不允许多人同时重复登陆
- hdu1104 BFS + 数论
- bootstrap的选项卡和选项卡的内容
- 矢量的概念
- 数据挖据十大算法之ID3算法(1)