Numbers

Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://acm.hdu.edu.cn/showproblem.php?pid=5522

Description

给n个数A1,A2....An{A}_{1},{A}_{2}....{A}_{n}A​1​​,A​2​​....A​n​​,从中选3个位置不同的数A,B和C,问是否有一种情况满足A-B=C.

Input

There are multiple test cases, no more than 1000 cases.
First line of each case contains a single integer n.(3≤n≤100).
Next line contains n integers A1,A2....An.(0≤Ai≤1000)

Output

For each case output "YES" in a single line if you find such i, j, k, otherwise output "NO"

Sample Input

3
3 1 2
3
1 0 2
4
1 1 0 2

Sample Output

YES
NO
YES

HINT

题意

题解:

就n^2暴力,先排序然后从大到小枚举i,把右边的数用一个数组标记其出现过,再枚举左边的数判断其加上Ai是否出现过.

代码

#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<map>
using namespace std; map<int,int> H;
int a[];
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
H.clear();
for(int i=;i<=n;i++)
scanf("%d",&a[i]),H[a[i]]++;
sort(a+,a++n);
int flag = ;
for(int i=;i<=n;i++)
{
H[a[i]]--;
for(int j=;j<i;j++)
if(H[a[j]+a[i]])
flag = ;
if(flag)
break;
}
if(flag)
printf("YES\n");
else
printf("NO\n");
}
}

HDU 5522 Numbers 暴力的更多相关文章

  1. HDU 5522 Numbers

    水题 #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> us ...

  2. HDU 6168 - Numbers | 2017 ZJUT Multi-University Training 9

    /* HDU 6168 - Numbers [ 思维 ] | 2017 ZJUT Multi-University Training 9 题意: .... 分析: 全放入multiset 从小到大,慢 ...

  3. Hdu oj 5522 Numbers 之解题报告

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABCwAAAL7CAIAAAC5m4NqAAAgAElEQVR4nOy9e7QdVZUvXH+RMcJVdJ

  4. hdoj 5522 Numbers

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5522 水题:暴力过 #include<stdio.h> #include<strin ...

  5. hdu 5726 GCD 暴力倍增rmq

    GCD/center> 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5726 Description Give you a sequence ...

  6. HDU 5510 Bazinga 暴力匹配加剪枝

    Bazinga Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5510 ...

  7. hdu 5077 NAND(暴力打表)

    题目链接:hdu 5077 NAND 题目大意:Xiaoqiang要写一个编码程序,然后依据x1,x2,x3的值构造出8个字符.如今给定要求生成的8个字符.问 说Xiaoqiang最少要写多少行代码. ...

  8. Educational Codeforces Round 23 C. Really Big Numbers 暴力

    C. Really Big Numbers time limit per test 1 second memory limit per test 256 megabytes input standar ...

  9. hdu 4291(矩阵+暴力求循环节)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4291 思路:首先保留求出循环节,然后就是矩阵求幂了. #include<iostream> ...

随机推荐

  1. hdu 3068(最长回文)

    题意:容易理解... 思路:可以用扩展kmp来做,但是我还没怎么弄懂,时间复杂度O(n*logn),而manacher算法,第一次听说,代码比较短,不难理解,和扩展kmp有点类似,时间复杂度为:O(n ...

  2. ylbtech-SubwayNav(地铁线路导航)-数据库设计

    ylbtech-DatabaseDesgin:ylbtech-SubwayNav(地铁线路导航)-数据库设计 DatabaseName:SubwayNav(地铁线路导航) Type:线路导航 1.A, ...

  3. http://blog.csdn.net/jbb0403/article/details/42102527

    http://blog.csdn.net/jbb0403/article/details/42102527

  4. IOS 类别与扩展的区别 (category & extensions)

    类别 .h @interface NSString(XXXXXX) -(NSInteger)getLen; @end .m @implementation NSString(XXXXXX) -(NSI ...

  5. asp.net MVC 安全性[笔记]

    1. 跨站脚本(XSS) 1.1 介绍 1.1.1 被动注入,利用输入html,javascript 等信息伪造链接,图片等使用提交信息,调转页面等 1.1.2 主动注入,黑客主动参与攻击,不会傻等倒 ...

  6. 查看linux服务器中的apache是否安装以及安装路径

    1.可以通过 apachectl -v 查看apache是否安装,如果安装了的话会显示版本号: 2.如果通过rpm包安装的话可以用  rpm -q  httpd 查看,如果安装的的话会显示包的名称

  7. UVALive 4763

    一开始,没敢写,感觉会超时...其实就是暴力搜索.DFS #include<iostream> #include<stdio.h> #include<string.h&g ...

  8. mybatis系列-11-一对多查询

    11.1     需求 查询订单及订单明细的信息. 11.2     sql语句 确定主查询表:订单表 确定关联查询表:订单明细表 在一对一查询基础上添加订单明细表关联即可. SELECT order ...

  9. hdfs 数据块重分布 sbin/start-balancer.sh -threshold

    数据块重分布sbin/start-balancer.sh -threshold <percentage of disk capacity>percentage of disk capa ...

  10. pomelo windows 环境

    1.先安装 Python; 通过Python 官网 http://www.python.org/getit/ 下载并安装最新版本. 然后将Python 的安装目录(如: C:\Program File ...