A. Bear and Three Balls

题目连接:

http://www.codeforces.com/contest/653/problem/A

Description

Limak is a little polar bear. He has n balls, the i-th ball has size ti.

Limak wants to give one ball to each of his three friends. Giving gifts isn't easy — there are two rules Limak must obey to make friends happy:

No two friends can get balls of the same size.
No two friends can get balls of sizes that differ by more than 2.
For example, Limak can choose balls with sizes 4, 5 and 3, or balls with sizes 90, 91 and 92. But he can't choose balls with sizes 5, 5 and 6 (two friends would get balls of the same size), and he can't choose balls with sizes 30, 31 and 33 (because sizes 30 and 33 differ by more than 2).

Your task is to check whether Limak can choose three balls that satisfy conditions above.

Input

The first line of the input contains one integer n (3 ≤ n ≤ 50) — the number of balls Limak has.

The second line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ 1000) where ti denotes the size of the i-th ball.

Output

Print "YES" (without quotes) if Limak can choose three balls of distinct sizes, such that any two of them differ by no more than 2. Otherwise, print "NO" (without quotes).

Sample Input

4
18 55 16 17

Sample Output

YES

Hint

题意

给你n个数,问你能不能从这些数里面抽出三个数

使得这三个数都不相同,且这三个数能够满足a[2]=a[1]+1,a[3]=a[2]+1

题解:

数据范围很小,怎么做都可以

可以直接排个序,去重,然后check就好了。

代码

#include<bits/stdc++.h>
using namespace std;int a[103],tot=0;
map<int,int> H;
int main()
{int n;scanf("%d",&n);for(int i=1;i<=n;i++){int x;scanf("%d",&x);if(H[x])continue;H[x]++;a[tot++]=x;}if(tot<3)return puts("NO"),0;sort(a,a+tot);for(int i=0;i+2<tot;i++){if(a[i]==a[i+1]-1&&a[i]==a[i+2]-2)return puts("YES"),0;}return puts("NO"),0;}

转载于:https://www.cnblogs.com/qscqesze/p/5296463.html

IndiaHacks 2016 - Online Edition (Div. 1 + Div. 2) A. Bear and Three Balls 水题相关推荐

  1. IndiaHacks 2016 - Online Edition (Div. 1 + Div. 2) C. Bear and Up-Down 暴力

    C. Bear and Up-Down 题目连接: http://www.codeforces.com/contest/653/problem/C Description The life goes ...

  2. VK Cup 2016 - Round 1 (Div. 2 Edition) A. Bear and Reverse Radewoosh 水题

    A. Bear and Reverse Radewoosh 题目连接: http://www.codeforces.com/contest/658/problem/A Description Lima ...

  3. html css样式div属性,div css

    DIV+CSS是WEB设计标准,它是一种网页的布局方法.与传统中通过表格(table)布局定位的方式不同,它可以实现网页页面内容与表现相分离.提起DIV+CSS组合,还要从XHTML说起.XHTML是 ...

  4. xHTML+div布局:三个div,两边div宽度固定,中间div宽度自适应

    xHTML+div经常考题:三个div,两边div宽度固定,中间div宽度自适应. 和大家分享一个实现方式: 1.html代码 1 <div class="dyleft"&g ...

  5. html div套div,Web前端开发技术之Div+Css基础

    今天我们的课程内容有: CSS在页面风格设计中的作用 多个HTML页面调用一个CSS文件 DIV的创建与应用 用DIV+CSS的方式来写HTML页面 传统HTML的缺点和现在Css的优势Html的不足 ...

  6. div嵌套div的居中问题

    2019独角兽企业重金招聘Python工程师标准>>> div嵌套div,我们经常都用.布局是基础,扎实的基础会让你在解决问题的时候更柔韵有余.这是我出来工作之后深深的领悟.下面是我 ...

  7. DIV或者DIV里面的图片水平与垂直居中的方法 - 站住,别跑 - 博客园

    DIV或者DIV里面的图片水平与垂直居中的方法 <div class="box"><img /> </div> 水平居中的常用方式: text- ...

  8. Codeforces Round #586 (Div. 1 + Div. 2) B. Multiplication Table 思维 + 公式

    传送门 文章目录 题意: 思路: 题意: 给你一个n∗nn*nn∗n的矩阵,每个位置由ai∗aja_i*a_jai​∗aj​得来,主对角线为000,让你求出来aia_iai​. n≤1e3n\le1e ...

  9. Codeforces Round #586 (Div. 1 + Div. 2) D. Alex and Julian 数学 + 思维

    传送门 文章目录 题意: 思路: 题意: 给你一个无限个点的坐标轴,一个集合BBB,如果存在∣i−j∣=bk|i-j|=b_k∣i−j∣=bk​的话,那么i,ji,ji,j之间就连边.现在问你至少要从 ...

最新文章

  1. Android 开源框架Universal-Image-Loader完全解析(一)--- 基本介绍及使用
  2. php zval_copy_static_var(),zval _ 引用计数 _ 变量分离 _ 写时拷贝
  3. 内网突破SSL嗅探的探究
  4. Wind7系统下 wifi设置
  5. css3中的background
  6. 【牛客 - 283F】出装方案(最小费用最大流)
  7. aws rds监控慢sql_AWS RDS SQL Server –启动新的数据库实例
  8. document.ready和window.onload
  9. Atitit vscode 调试php vscode使用法 目录 1. 直接debug没反应,或者打开扩展列表 1 2. 调试配置法 1 2.1. Debug》》Add cfg php 1 2.2.
  10. 常见的.net误解 1-1 字符串是不可修改的(immutable)
  11. 字节教育开辟新业务线,推出“闪电搜题”App可拍题和自习
  12. 清理redis集群的所有数据
  13. unity3d 地面印花_unity冬季场景地面地形白雪纹理材质贴图游戏素材Winter Ground Pack v1.1...
  14. 天大18年c语言离线作业,2018春 Python语言程序设计(天津大学仁爱学院)-中国大学mooc-题库零氪...
  15. Windows配置互联网访问检测服务器-IspSrv
  16. 金融行业数据安全及合规使用
  17. matlab期末数字图像处理小工具
  18. 案例解析:广域网加速在校园网中的应用
  19. 让大数据“觉醒”,数据中台与数据开发平台成为企业关键战略
  20. 【数据异常校验】肖维勒准则(Chauvenet Criterion)处理异常数据

热门文章

  1. HTML5 跨文档消息传输
  2. 在SecureCRT中,hbase shell不能回退的问题
  3. 【Python-ML】最小二乘法
  4. 【Python-ML】神经网络激励函数-双曲正切(hyperbolic tangent,tanh)函数
  5. Linux命令free解读
  6. java 向上取整_java 中的异常处理和常用类使用
  7. Explore the Service Console
  8. Windows 技术篇:cmd使用过程中输入字母突然不显示光标的原因与解决方法
  9. BAT批处理文件无法运行提示“/E /I /Y ‘XCOPY‘ 不是内部或外部命令,也不是可运行的程序或批处理文件”解决方法
  10. javascript中not defined、undefined、null以及NaN的区别