YY's new problem

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

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
 
Source
 
Recommend
xubiao
题意:就是找出数列中是否有满足p[i1]-p[i2]=p[i2]-p[i3], 1<=i1<i2<i3<=N.的存在
题解:先将公式转化一下,转化为(p[i1]+p[i3])/2=p[i2]。即找到两个数中间存在一个数为他们的一半。
   用数组嵌套记录下数的位置和值,a数组代表输入的值,b数组代表输入的值的位置。二重i,j循环
   遍历数组,如果a[i]和a[j]的和s是奇数那么肯定不存在一个数c的二倍等于他们的和,因为c的二倍
   是偶数。所以continue。如果是偶数那么数c的值肯定是一定的,一定是(a[i]+a[j])/2,现在找数
   c是不是在a[i]和a[j]中间,如果在就存在这种情况了。这个时候就要用到b数组了,因为b数组是记
   录元素下标的。用b数组判断是不是在中间就行了,如果找到了就用flag标记一下break输出就行了。
#include <iostream>
#include <stdio.h>
using namespace std;
int main()
{
int i,j,n,t,a[],b[],flag,s;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
flag=;
for(i=;i<n;i++)
{
scanf("%d",&a[i]);
b[a[i]]=i;
}
for(i=;i<n;i++)
for(j=i+;j<n;j++)
{
s=a[i]+a[j];
if(s%)
continue;
if(b[s/]>i&&b[s/]<j)
{
flag=;
break;
}
if(flag)
break;
}
if(flag)
printf("Y\n");
else
printf("N\n");
}
return ;
}

HDU 3833 YY's new problem ()的更多相关文章

  1. HDU 3833 YY's new problem(换种思路的模拟,防超时)

    题目链接 用p[a]保存的是输入的a在第p[a]个,  然后根据差值查找. #include<stdio.h> #include<string.h> int main() { ...

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

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

  3. HDU 4974 A simple water problem(贪心)

    HDU 4974 A simple water problem pid=4974" target="_blank" style="">题目链接 ...

  4. HDU 5572 An Easy Physics Problem (计算几何+对称点模板)

    HDU 5572 An Easy Physics Problem (计算几何) 题目链接http://acm.hdu.edu.cn/showproblem.php?pid=5572 Descripti ...

  5. HDU 3861 The King’s Problem(强连通+二分图最小路径覆盖)

    HDU 3861 The King's Problem 题目链接 题意:给定一个有向图,求最少划分成几个部分满足以下条件 互相可达的点必须分到一个集合 一个对点(u, v)必须至少有u可达v或者v可达 ...

  6. hdu 5349 MZL's simple problem

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5349 MZL's simple problem Description A simple proble ...

  7. HDU 5924 Mr. Frog’s Problem 【模拟】 (2016CCPC东北地区大学生程序设计竞赛)

    Mr. Frog's Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Other ...

  8. HDU 4978 A simple probability problem

    A simple probability problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K ( ...

  9. 【HDU 5572 An Easy Physics Problem】计算几何基础

    2015上海区域赛现场赛第5题. 题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=5572 题意:在平面上,已知圆(O, R),点B.A(均在圆外),向量 ...

随机推荐

  1. [转]ubuntu安装光盘修复grub-rescue引导失败问题

    Reference:http://liujianqiao398.blog.163.com/blog/static/181827257201292775649815/ 1.步骤一 以试用方式进入ubun ...

  2. omnetpp inet

    http://blog.csdn.net/midie/article/details/5086983 omnetpp inet 自带了Mingw编译环境,而不再需要Visual C编译环境了.事实上, ...

  3. ci连贯操作的limit两个参数和sql是相反的

    ci连贯操作的limit两个参数和sql是相反的 db->where("name =",'mary')->ge() name后面要有个空格否则报错当为一个字段 -> ...

  4. 初学Hibernate持久化

    hibernate三种持久化对象状态:(持久化对象:Persistent Object=POJO + hbm映射) 1.瞬时状态(临时状态或自由态):PO对象刚创建(即new)开始进入瞬时状态,此时对 ...

  5. java常见异常类图(分类了Error/RuntimeExecption、check Exception)

    版权:欧初权 http://www.cnblogs.com/langtianya/p/4435537.html

  6. ASP.NTE 5 Target framework dnx451 and dnxcore50(转)原文:http://www.cnblogs.com/xishuai/p/aspnet5-target-framework-dnx451-and-dnxcore50.html

    中文不知如何定义标题,所以干脆就直接贴出关键字,在 ASP.NTE 5 项目的 project.json 配置文件中,会有这样的定义: "frameworks": { " ...

  7. php的urlencode()URL编码函数浅析

    URLEncode:是指针对网页url中的中文字符的一种编码转化方式,最常见的就是Baidu.Google等搜索引擎中输入中文查询时候,生成经过Encode过的网页URL.   URLEncode的方 ...

  8. Zookeeper Invalid config, exiting abnormally

    Zookeeper Invalid config, exiting abnormally     出现 Invalid config, exiting abnormally 的情况可能有3个: 是否开 ...

  9. js打印(控件)及多种方式

    非常好用的LODOP打印控件 Lodop打印控件简单使用方法 1.安装. 2.调用LodopFuncs.js文件. 3.增加OBJECT对象 <script language="jav ...

  10. [codeforces 528]B. Clique Problem

    [codeforces 528]B. Clique Problem 试题描述 The clique problem is one of the most well-known NP-complete ...