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 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;
}
IndiaHacks 2016 - Online Edition (Div. 1 + Div. 2) A. Bear and Three Balls 水题的更多相关文章
- IndiaHacks 2016 - Online Edition (Div. 1 + Div. 2) B. Bear and Compressing
B. Bear and Compressing 题目链接 Problem - B - Codeforces Limak is a little polar bear. Polar bears h ...
- IndiaHacks 2016 - Online Edition (Div. 1 + Div. 2) E - Bear and Forgotten Tree 2 链表
E - Bear and Forgotten Tree 2 思路:先不考虑1这个点,求有多少个连通块,每个连通块里有多少个点能和1连,这样就能确定1的度数的上下界. 求连通块用链表维护. #inclu ...
- IndiaHacks 2016 - Online Edition (Div. 1 + Div. 2) E. Bear and Forgotten Tree 2 bfs set 反图的生成树
E. Bear and Forgotten Tree 2 题目连接: http://www.codeforces.com/contest/653/problem/E Description A tre ...
- IndiaHacks 2016 - Online Edition (Div. 1 + Div. 2) D. Delivery Bears 二分+网络流
D. Delivery Bears 题目连接: http://www.codeforces.com/contest/653/problem/D Description Niwel is a littl ...
- 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 ...
- IndiaHacks 2016 - Online Edition (Div. 1 + Div. 2) B. Bear and Compressing 暴力
B. Bear and Compressing 题目连接: http://www.codeforces.com/contest/653/problem/B Description Limak is a ...
- 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 ...
- 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 ...
随机推荐
- 超详细的Java面试题总结(四 )之JavaWeb基础知识总结
系列文章请查看: 超详细的Java面试题总结(一)之Java基础知识篇 超详细的Java面试题总结(二)之Java基础知识篇 超详细的Java面试题总结(三)之Java集合篇常见问题 超详细的Java ...
- ubuntu遇到的 the system is runing low-graphics mode 问题
不知道修改了什么,然后开机显示the system is runing low-graphics mode 看过博客使用如下方法成功进入系统,但是显示分辨率很低,显示 built-in display ...
- ThoughtWorks代码挑战——FizzBuzzWhizz游戏 通用高速版(C/C++ & C#)
最早看到这个题目是从@ 程序媛想事儿(Alexia) 的 最难面试的IT公司之ThoughtWorks代码挑战——FizzBuzzWhizz游戏 开始的,然后这几天陆陆续续有N个小伙伴发表了自己的文章 ...
- redis aof文件过大问题
http://www.itnose.net/detail/6682725.html 最近新安装了一台redis,版本为redis-3.2.5 数据盘用的是固态硬盘. 之前用的是普通硬盘,redis日志 ...
- vue数据传递--我有特殊的实现技巧
最近碰到了比较多的关于vue的eventBus的问题,之前定技术选型的时候也被问到了,vuex和eventBus的使用范围.所以简单的写一下.同时有一种特殊的实现方案. 有这么几种数据传递方式,vue ...
- POJ 1511 Invitation Cards(Dijkstra(优先队列)+SPFA(邻接表优化))
题目链接:http://poj.org/problem?id=1511 题目大意:给你n个点,m条边(1<=n<=m<=1e6),每条边长度不超过1e9.问你从起点到各个点以及从各个 ...
- Expert C Programming 阅读笔记(CH2)
P33 Bugs are by far the largest and most successful class of entity, with nearly a million known ...
- Windows Azure 初体验
最近看到windows azure 在做活动,只需花一块钱就可以体验一个月的windows azure. 于是,我就注册了一个账号也尝试一把云时代,传送门. 注册很简单的,成功后可以看到这个界面. 然 ...
- 第二章:监控属性(Observables)
关于Knockout的3个重要概念(Observables,DependentObservables,ObservableArray),本人无法准确表达它的准确含义,所以暂定翻译为(监控属性.依赖监控 ...
- logstash收集nginx日志
(1)安装nginx 1.安装nginx yum install epel-release -y yum install nginx -y 2.修改日志文件格式为json #vim /etc/ngin ...