CodeForces 653A Bear and Three Balls 暑期小练习

原创 2016年05月31日 17:21:22

Bear and Three Balls


Description

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

Limakwants to give one ball to each of his three friends. Giving gifts isn'teasy — 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.

Forexample, Limak can choose balls with sizes 45 and 3,or balls with sizes 9091 and 92.But he can't choose balls with sizes 55and 6 (twofriends would get balls of the same size), and he can't choose balls with sizes 3031 and 33 (becausesizes 30 and 33 differby more than 2).

Yourtask is to check whether Limak can choose three balls that satisfy conditionsabove.

Input

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

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

Output

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

Sample Input

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

 

题意:给三个人送礼物,送礼物的编号是连续的三个整数

 

 

思路:数据量不是很大,直接数组填充出现的数字后判断即可。

 

 第一次那么容易A CF的题目昂

代码:

 

/*=============================AC情况===============================*/
/*题目网址:   */
/*时间: */
/*心得:  */

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define G 1009

int MIN(int x,int y) {
	return x<y? x:y;
}

int main() {
	int n,t,min,flag;
	int wqs[G];
	while(scanf("%d",&n)!=EOF) {
		min=10000;
		memset(wqs,0,sizeof(wqs));
		for(int j=0; j<n; j++) {
			scanf("%d",&t);
			min=MIN(t,min);
			wqs[t]=1;//该数字出现过
		}
		for(int j=min; j<G-1; j++) {
			if(wqs[j]&&wqs[j+1]&&wqs[j+2]) {//存在三个连续的数字
				flag=1;
				break;
			}
			flag=0;
		}
		if(flag)
			puts("YES");
		else
			puts("NO");
	}
	return 0;
}

/*********************************测试数据*********************************


**************************************************************************/

 

 

版权声明:就这些 Code ,尽管看。PS->只会敲代码的大男孩,是没有女孩子喜欢你的。。。。

Codeforces 653A: Bear and Three Balls(技巧,水)

A. Bear and Three Balls time limit per test 2 seconds memory limit per test 256 megabyte...
  • zugofn
  • zugofn
  • 2016年06月06日 23:37
  • 338

Bear and Three Balls CodeForces - 653A

Limak is a little polar bear. He has n balls, the i-th ball has size ti.Limak wants to give one ball...
  • DNMTOOBA
  • DNMTOOBA
  • 2017年07月23日 10:07
  • 103

codeforces 653A . Bear and Three Balls

Bear and Three Balls(sort) Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d ...
  • neversayno_yl
  • neversayno_yl
  • 2016年07月19日 10:44
  • 76

【CodeForces】[653A]Bear and Three Balls

因为有 1 2 2 3 这种数据 所以不能简单的进行排序查找 可以先去除重复的数字...
  • u011493189
  • u011493189
  • 2016年04月07日 22:16
  • 111

CodeForces 653A Bear and Three Balls

O - O Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Statu...
  • yao1373446012
  • yao1373446012
  • 2016年05月30日 12:54
  • 381

CodeForces 653A Bear and Three Balls

Bear and Three Balls time limit per test 2 seconds memory limit per test 256 megabytes ...
  • CHRISTINA_ERZA
  • CHRISTINA_ERZA
  • 2016年08月03日 20:19
  • 83

【codeforces 653A】Bear and Three Balls

Bear and Three Balls Limak is a little polar bear. He has n balls, the i-th ball has size ti. Li...
  • Selina_lxh
  • Selina_lxh
  • 2017年08月08日 17:21
  • 80

Codeforces 653A Bear and Three Balls

题目:http://codeforces.com/problemset/problem/653/A 代码: #include #include #include using namespace ...
  • qq_32473657
  • qq_32473657
  • 2016年03月22日 22:46
  • 103

A. Bear and Three Balls CodeForces 653A

Limak is a little polar bear. He has n balls, the i-th ball has size ti. Limak wants to give one ...
  • q923714892
  • q923714892
  • 2016年08月22日 20:22
  • 77

【IndiaHacks 2016 - Online Edition (Div 1 + Div 2) ErrichtoA】【水题】Bear and Three Balls 是否有数值相差1的三个数

Bear and Three Balls time limit per test 2 seconds memory limit per test 256 megabytes ...
  • snowy_smile
  • snowy_smile
  • 2016年03月21日 09:16
  • 367
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:CodeForces 653A Bear and Three Balls 暑期小练习
举报原因:
原因补充:

(最多只允许输入30个字)