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. SpringMVC数据库链接池,以及其他相关配置

    1.applicationContext.xml <?xml version="1.0" encoding="UTF-8"?> <beans ...

  2. linux内核数据结构学习总结

    目录 . 进程相关数据结构 ) struct task_struct ) struct cred ) struct pid_link ) struct pid ) struct signal_stru ...

  3. SPOJ Pouring Water

    传送门 POUR1 - Pouring water #gcd #recursion Given two vessels, one of which can accommodate a litres o ...

  4. POJ1745Divisibility(01背包思想)

    Divisibility Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 11151   Accepted: 3993 Des ...

  5. jquery------显示加载的js时出现中文乱码解决方法

    方法: 把my.js文件复制出来,用记事本打开,再另存为的时候设置编码格式为utf-8即可

  6. electron加载jquery报错问题

    <!-- Insert this line above script imports --> <script>if (typeof module === 'object') { ...

  7. CentOS 6.4 32位系统 LAMP(Apache+MySQL+PHP)安装步骤

    先来解释一下,什么是 LAMP.正如标题所言,LAMP 实际上就是 Linux.Apache.MySQL.PHP 四个名称的缩写,当然最后一个 “P” 还有其他说法是 Perl 或者 Python.不 ...

  8. zabbix 汉化

    zabbix2.x的版本自带汉化,3.x的版本也可以通过修改配置文件强制使用自带的汉化,但是不管哪种,翻译的精准度令人费解:偶然发现一个专门翻译zabbix的网站https://www.zabbix. ...

  9. Zabbix 监控 Nginx 状态

    简介: 如何使用 Zabbix 监控 Nginx 状态 ? 1.获取 Nginx 状态( HTTP Stub Status ) shell > /usr/local/nginx/sbin/ngi ...

  10. 工具类HttpServerUtility

    在ASP.NET服务器上提供一个辅助的工具类HttpServerUtility,该类提供了一些处理请求的辅助方法. MapPath:计算网站中虚拟路径所对应的物理文件路径. HtmlEncode:将H ...