日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

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

發(fā)布時(shí)間:2025/4/14 编程问答 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 IndiaHacks 2016 - Online Edition (Div. 1 + Div. 2) A. Bear and Three Balls 水题 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

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個(gè)數(shù),問你能不能從這些數(shù)里面抽出三個(gè)數(shù)

使得這三個(gè)數(shù)都不相同,且這三個(gè)數(shù)能夠滿足a[2]=a[1]+1,a[3]=a[2]+1

題解:

數(shù)據(jù)范圍很小,怎么做都可以

可以直接排個(gè)序,去重,然后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;}

轉(zhuǎn)載于:https://www.cnblogs.com/qscqesze/p/5296463.html

總結(jié)

以上是生活随笔為你收集整理的IndiaHacks 2016 - Online Edition (Div. 1 + Div. 2) A. Bear and Three Balls 水题的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。