链接:http://codeforces.com/problemset/problem/653/A

                                                                                     A. Bear and Three Balls
                                                                                       time limit per test

2 seconds

                                                                                     memory limit per test

256 megabytes

                                                                                         input

standard input

                                                                                           output

standard output

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 and6 (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).

Examples
input
4
18 55 16 17
output
YES
input
6
40 41 43 44 44 44
output
NO
input
8
5 972 3 4 1 4 970 971
output
YES
Note

In the first sample, there are 4 balls and Limak is able to choose three of them to satisfy the rules. He must must choose balls with sizes18, 16 and 17.

In the second sample, there is no way to give gifts to three friends without breaking the rules.

In the third sample, there is even more than one way to choose balls:

  1. Choose balls with sizes 3, 4 and 5.
  2. Choose balls with sizes 972, 970, 971

AC代码:

不是原创代码,看的百度博客上的思路,自己当时不会做。。。。现在想想其实不难,,,

 #include<stdio.h>
#include<algorithm>
using namespace std;
bool cmp(int x,int y)
{ return x<y;
}
int main()
{
int n,i,j,k,d,s,e,q;
int a[];
while(scanf("%d",&n)!=EOF)
{
k=;
for(i=;i<n;i++)
scanf("%d",&a[i]);
sort(a,a+n,cmp);
for(i=;i<n-;i++)
{
for(j=i+;j<n;j++)
{
s=a[j]-a[i];
if(s==||s==)
{
for(q=j+;q<n;q++)
{
d=a[q]-a[j];
e=a[q]-a[i];
if((e==)&&(d==))
k++;
} }
}
}
if(k>) printf("YES\n");
else printf("NO\n");
}
return ;
}

Bear and Three Balls的更多相关文章

  1. codeforces 653A Bear and Three Balls

    A. Bear and Three Balls time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

  2. 【codeforces】Bear and Three Balls(排序,去重)

    Bear and Three Balls Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I6 ...

  3. IndiaHacks 2016 - Online Edition (Div. 1 + Div. 2) A. Bear and Three Balls 水题

    A. Bear and Three Balls 题目连接: http://www.codeforces.com/contest/653/problem/A Description Limak is a ...

  4. codeforces 653A A. Bear and Three Balls(水题)

    题目链接: A. Bear and Three Balls time limit per test 2 seconds memory limit per test 256 megabytes inpu ...

  5. IndiaHacks 2016 - Online Edition (Div. 1 + Div. 2)——A - Bear and Three Balls(unique函数的使用)

    A. Bear and Three Balls time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

  6. CodeForces 653 A. Bear and Three Balls——(IndiaHacks 2016 - Online Edition (Div. 1 + Div. 2))

    传送门 A. Bear and Three Balls time limit per test 2 seconds memory limit per test 256 megabytes input ...

  7. H - Bear and Three Balls

    Limak is a little polar bear. He has n balls, the i-th ball has size ti. Limak wants to give one bal ...

  8. Codeforces 653A Bear and Three Balls【水题】

    题目链接: http://codeforces.com/problemset/problem/653/A 题意: 给定序列,找是否存在连续的三个数. 分析: 排序~去重~直接判断~~ 代码: #inc ...

  9. C. Bear and Colors

    C. Bear and Colors time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

随机推荐

  1. MySQL访问控制实现原理

    MySQL访问控制实现原理 MySQL 访问控制实际上由两个功能模块共同组成,从第一篇的第二章架构组成中可以看到,一个是负责 “看守 MySQL 大门”的用户管理模块,另一个就是负责监控来访者每一个动 ...

  2. 使用javac编译zookeeper项目

    这里记录zookeeper编译源代码上的一些细节的问题. 网上不少关于如何使用ant eclipse来构建zookeeper对应的eclipse工程的记录.这里就不再过多赘述.只做简单阐述. 这里主要 ...

  3. [leetcode-592-Fraction Addition and Subtraction]

    Given a string representing an expression of fraction addition and subtraction, you need to return t ...

  4. HTTP通过请求和响应的交换达成通信

    1. 通过请求和响应的交换达成通信 首先我们来看一个HTTP请求报文: GET/index.htm HTTP/1.1 HOST : hacker.jp HTTP协议起始行开头的GET表示请求访问服务器 ...

  5. Hadoop出现的错误及处理

    1.local host is: (unknown); destination host is: "yun-ubuntu":8031; 原因:yun-ubuntu这个host 并不 ...

  6. Watson Explorer Analytical Components 1

    Introduction: IBM Watson Explorer Analytical Components(AC) which is part of the IBM Watson Explorer ...

  7. 京东JOS API 接入使用笔记

    商户开设了京东店.淘宝店,最近打算使用京东物流,需要使用京东仓库(京东店的订单使用京仓发货,淘宝等其他店使用京东云仓)发货,所以得从自家的ERP与京东沧海(ECLP)API对接,实现收发存. 首先得在 ...

  8. HTML5 drag和drop的亲手实践

    起因 最近在公司打杂的时候,突然分到了一个锅,就是要支持一个新的功能:用户可以通过拖曳组件来改变组件的顺序.因此,这阵子就看了一下网上的一些drag和drog的文章以及W3C的介绍,然后自己亲手实践了 ...

  9. 流畅python学习笔记:第十章:序列的修改,散列和切片

    前面在介绍了类的很多内置方法,比如__add__,__eq__,这里继续介绍类的两个内置方法,这2个内置方法可以将一个类实例变成一个序列的形式.代码如下 class vector(object):   ...

  10. AugularJS从入门到实践(二)

      前  言  前端    AngularJS是为了克服HTML在构建应用上的不足而设计的.(引用百度百科) 本篇学习主要有两个部分: ①[AngularJS 过滤器]   ②[AngularJS  ...