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. 【poj3348】 Cows

    http://poj.org/problem?id=3348 (题目链接) 题意 给出平面上n个点,以这n个点中的一些围成的多边形面积 div 50的最大值. Solution 凸包求面积. 很好做, ...

  2. KTHREAD 线程调度 SDT TEB SEH shellcode中DLL模块机制动态获取 《寒江独钓》内核学习笔记(5)

    目录 . 相关阅读材料 . <加密与解密3> . [经典文章翻译]A_Crash_Course_on_the_Depths_of_Win32_Structured_Exception_Ha ...

  3. Win7 + ubuntu14.04 双系统

    安装主要分为以下几步:一. 下载Ubuntu 14.04镜像软件:二. 制作U盘启动盘:三. 安装Ubuntu系统:四. 用EasyBCD 创建启动系统. 1. 下载 Ubuntu 14.04 直接到 ...

  4. another app is currently holding the yum lock;waiting for it to exit解决

    有时用yum升级一些文件时,会出现以下情况:   another app is currently holding the yum lock;waiting for it to exit...   可 ...

  5. UVa OJ 194 - Triangle (三角形)

    Time limit: 30.000 seconds限时30.000秒 Problem问题 A triangle is a basic shape of planar geometry. It con ...

  6. TFS 配置 报表权限问题

    通过[项目门户网站]访问,却被提示ReportService权限不足时, 提示:处理报表时出错. (rsProcessingAborted)  对数据集 “dsiteration” 执行查询失败 同样 ...

  7. vim tab 和4个空格

    在.vimrc中添加以下代码后,重启vim即可实现按TAB产生4个空格:set ts=4  (注:ts是tabstop的缩写,设TAB宽4个空格)set expandtab 对于已保存的文件,可以使用 ...

  8. ios开发 网络编程浅析(一)

    iphone包含了很多框架和库,从底层的套接字到不同层次的封装,可以方便地给程序添加网络功能. (1)BSD套接字.最底层的套接字,这是Unix网络开发常用的API.如果从其他系统移植程序,而程序用的 ...

  9. Spark-1.0.0 standalone分布式安装教程

    Spark目前支持多种分布式部署方式:一.Standalone Deploy Mode:二Amazon EC2.:三.Apache Mesos:四.Hadoop YARN.第一种方式是单独部署,不需要 ...

  10. 繁华模拟赛 David与阶乘

    #include<cstdio> #include<iostream> #include<algorithm> #include<cstring> #i ...