标签:
4 1 3 2 2 2 1 1
YES NO
1 #include <cstdio> 2 #include <cstdlib> 3 #include <cstring> 4 5 int N; 6 int A[10001]; 7 8 int main() { 9 int tmp; 10 while (scanf("%d", &N) != EOF) { 11 memset(A, 0, sizeof(A)); 12 bool flag = false;; 13 int min = 10000, max = 0; 14 for (int i = 0; i < N; ++i) { 15 scanf("%d", &tmp); 16 ++A[tmp]; 17 min = min > tmp ? tmp : min; 18 max = max > tmp ? max : tmp; 19 } 20 tmp = 0; 21 for (int i = min; i <= max; ++i) { 22 if (A[i] == 0) { 23 flag = false; 24 break; 25 } 26 tmp = A[i] - tmp; 27 if (tmp <= 0 && i != max) { 28 flag = false; 29 break; 30 } 31 if (tmp ==0 && i == max) { flag = true;} 32 } 33 if (flag) { 34 printf("YES\n"); 35 } else { 36 printf("NO\n"); 37 } 38 } 39 return 0; 40 } 41 42 /************************************************************** 43 Problem: 1377 44 User: hupo250 45 Language: C++ 46 Result: Accepted 47 Time:30 ms 48 Memory:1060 kb 49 ****************************************************************/
标签:
原文地址:http://www.cnblogs.com/easonliu/p/4328681.html