IndiaHacks 2016 - Online Edition (Div. 1 + Div. 2) A. Bear and Three Balls 水题
2016-03-19 21:53
453 查看
A. Bear and Three Balls
题目连接:
http://www.codeforces.com/contest/653/problem/ADescription
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
418 55 16 17
Sample Output
YESHint
题意
给你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; }
相关文章推荐
- 别傻了,人家离职你也离
- 公告 我的另外一个博客
- 搬圆桌问题
- const, static, const static
- jquery扩展方法
- Harmonic Number(调和级数+欧拉常数)
- 大数据量高并发访问的数据库优化方法
- Http协议与TCP协议简单理解
- 创建第一个Spring MVC程序helloworld
- Linux 终端的一些动画命令
- [Coursera]计算机组成_Week3_Mips_Q2
- 初识MVC
- 北化oj 2106-程序改错 - scanf中%c
- Python Static method vs class method
- POJ 1797 kruskal 算法
- eclipse不能新建server
- 第五十七天
- linux输入子系统概念介绍
- 教你如何使用Java泛型
- codeforces_620C. Pearls in a Row