【CodeForces】[653A]Bear and Three Balls

Problem Description

Loading...

Problem Analysis

Because there is data like
1 2 2 3
so you can’t simply sort and search
you can remove the duplicate numbers first

cpp
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include<stdio.h>
#include<algorithm>
using namespace std;
int a[55];
bool flag[55];
int n;
bool find() {
	sort(a,a+n);
	for(int i=0; i<n-2; i++)
		if(a[i]+1==a[i+1]&&a[i+1]+1==a[i+2])
			return true;
	return false;
}
int main() {
	while(scanf("%d",&n)!=EOF) {
		for(int i=0; i<n; i++)
			flag[i]=false;
		for(int i=0; i<n; i++) {
			scanf("%d",&a[i]);
			if(flag[a[i]]) {
				i--;
				n--;
			} else
				flag[a[i]]=true;
		}
		if(find())
			printf("YES\n");
		else
			printf("NO\n");
	}
	return 0;
}

Problem link:【CodeForces】[653A]Bear and Three Balls

This post is licensed under CC BY-NC-SA 4.0. If it helped, or if you have anything to say, the comment box below is open.
Page views —
Unique visitors —

Loading...