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 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).
Examples
4
18 55 16 17
YES
6
40 41 43 44 44 44
NO
8
5 972 3 4 1 4 970 971
YES 纯数学思维题目。。。写这个题目的目的 主要是有个去重的函数
#include<cstdio>
#include<cstring>
#include<cmath>
#include<queue>
#include<algorithm>
using namespace std;
int s[];
int main()
{
int n;
scanf("%d",&n);
for(int i=;i<n;i++)
{
scanf("%d",&s[i]);
} sort(s,s+n); int len=unique(s,s+n)-s;//去重 int flog=; for(int i=;i<len;i++)
{
if(s[i+]==s[i]+&&s[i+]==s[i+]+)
{
flog=;
break;
}
}
if(flog==)
printf("YES\n");
else
printf("NO\n");
return ;
}
H - Bear and Three Balls的更多相关文章
- 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 ...
- Bear and Three Balls
链接:http://codeforces.com/problemset/problem/653/A ...
- 【codeforces】Bear and Three Balls(排序,去重)
Bear and Three Balls Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I6 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- Codeforces 653A Bear and Three Balls【水题】
题目链接: http://codeforces.com/problemset/problem/653/A 题意: 给定序列,找是否存在连续的三个数. 分析: 排序~去重~直接判断~~ 代码: #inc ...
- Tkinter 项目-屏保
参考教程,以及网上资料,针对小白更好理解 关于tkinter的屏保涉及的知识点和思想 项目分析: 屏保启动方式:手动,自动 敲击键盘或者移动鼠标后,或者其他引发事件,则停止 如果屏保是一幅画的话,则没 ...
随机推荐
- 六、深浅拷贝与while循环
一.深浅拷贝 3.1 浅copy: 浅copy是把原列表第一层的内存地址不加区分完全copy一份给新列表 用法: list1=[ 'egon', 'lxx', [1,2] ] list2=list1. ...
- Go语言库系列之flag
背景 终端(命令行)操作是程序员的必备技能,但是你知道怎么通过golang制作出如下命令吗? $ flag girl -h Usage of girl: -height int 身高 (default ...
- java——构造器理解
构造器理解 什么是构造器 构造器也叫构造方法:用于对象的初始化: 写构造器注意事项 构造器名与类名一致:有返回值但是不能定义返回类型(返回值类型是本类,可以加一个空的return): 构造器的调用 通 ...
- 关于C#中Partial局部类型关键字的使用
虽然之前在做Winform开发时候,经常遇到Partial关键字,但是最近在代码中看到使用Partial将同名类文件写在多个源文件中,因此想要记录下Partial的详细使用. Partial type ...
- Ubuntu虚拟机查看文件,目录颜色详解
查看文件 查看Home(不是home)目录下文件: [duanyongchun@localhost ~]$ ls 查看根目录下文件: [duanyongchun@localhost ~]$ cd / ...
- 模块 jieba结巴分词库 中文分词
jieba结巴分词库 jieba(结巴)是一个强大的分词库,完美支持中文分词,本文对其基本用法做一个简要总结. 安装jieba pip install jieba 简单用法 结巴分词分为三种模式:精确 ...
- Blazor入门笔记(2)-分部类组件与组件的继承
1.前言 本文接自Blazor的组件(1)-从0构建一个组件 2.分部类组件 Razor组件你可理解为就是一个类名与文件名相同的类,因此,可以新建一个同名的partial类,将组件中@code里面的代 ...
- 徒手生撸一个验证框架,API 参数校验不再怕!
你们之中大概率早已练就了代码的拷贝.粘贴,无敌的码农神功,其实做久了业务功能开发,练就这两个无敌神功,那是迟早的事儿.今天先抛一个小问题,来打通你的任督二脉,就是很好奇的问一下:业务功能开发中,输入参 ...
- ensp,acl访问控制列表
ACL分类: 基本ACL 编号范围: 2000-2999 参数:源ip地址 高级ACL 编号范围: 3000-3999 参数:源ip地址,目的ip地址,源端口,目的端口等 二层ACL ...
- 关于Tkinter的介绍
Introduction to Tkinter 原英文教程地址zetcode.com In this part of the Tkinter tutorial, we introduce the Tk ...