C1. Nice array
time limit per test
2 seconds
memory limit per test
64 megabytes
input
standard input
output
standard output
Let’s call an array ‘nice’ if the result of some permutation of it, you can get a series of numbers that form an arithmetic progression. I want to know whether the specified array is nice.
Input
The first line of the input file contains a natural n (2 < = n < = 100) The second string contains n integers ( - 1000 < = ai < = 1000)
Output
In a single line of output file output "YES" or "NO" (without the quotes) - depending on whether the array of nice
Sample test(s)
input
3 2 3 1
output
YES
input
3 2 3 2
output
NO
Note
In the first test array can be written as a sequence of 1 2 3 - arithmetic progression with difference 1, the second is impossible.
codeforces easy round problem C1 - Nice Array Solution : http://codeforces.com/gym/200470/submission/6100552
#include <iostream> #include <cstdio> #include <cstdlib> using namespace std; int cmp(const void *a, const void *b) { return (*(int *)a - *(int *)b);} int main() { int a, b[2005], cnt, c; scanf("%d", &a); cnt=0; for(int i=0; i<a; i++) scanf("%d", &b[i]); qsort(b, a, sizeof(int), cmp); c=b[1]-b[0]; for(int i=1; i<a; i++) { if(b[i]-b[i-1]==c) cnt++; } if(cnt+1==a) printf("YES"); else printf("NO"); return 0; }
No comments:
Post a Comment