-
Title Description:
-
Chenbo a difficult question when writing a paper: How to transform a given integer sequence into a slow sequence: that is, any two adjacent elements have a difference of 1, and the 1th element differs from the last element by 1. Transformation refers to the order of the elements in the sequence of the original integers. For example, the integer sequence 1,3,2,2 can be transformed into a slow-variable sequence 1,2,3,2. The difference between (-), (2,3), (3,2) is 1, the 1th element and the last element differ by 1. Chenbo thought for a long time, even if he is wise Shenwu, still want to let everybody help a small favor: to judge whether a given integer sequence can be transformed into a slow variable sequence.
-
Input:
-
Each test file contains multiple test cases, two rows per test case, the first row containing an integer n, representing the length of the original integer sequence, and the second line is a space-separated n integer representing the sequence of integers. Where we can guarantee 2 <= N <= 10^5, each integer greater than or equal to 1 and less than or equal to 10000.
-
Output:
-
for each integer sequence, if it is a slow sequence or can be transformed into a slow sequence, output yes, otherwise output No.
-
Sample input:
-
41 3 2) 221 1
-
Sample output:
-
YESNO
-
Answering:
-
problem solving problems? to discuss the subject of discussion please visit: http://t.jobdu.com/thread-8100-1-1.html
1#include <cstdio>2#include <cstdlib>3#include <cstring>4 5 intN;6 inta[10001];7 8 intMain () {9 inttmp;Ten while(SCANF ("%d", &n)! =EOF) { Onememset (A,0,sizeof(A)); A BOOLFlag =false;; - intMin =10000, max =0; - for(inti =0; i < N; ++i) { thescanf"%d", &tmp); -++a[tmp]; -min = min > tmp?tmp:min; -max = max > tmp?max:tmp; + } -TMP =0; + for(inti = min; I <= Max; ++i) { A if(A[i] = =0) { atFlag =false; - Break; - } -TMP = A[i]-tmp; - if(TMP <=0&& I! =max) { -Flag =false; in Break; - } to if(TMP = =0&& i = = max) {flag =true;} + } - if(flag) { theprintf"yes\n"); *}Else { $printf"no\n");Panax Notoginseng } - } the return 0; + } A the /************************************************************** + problem:1377 - user:hupo250 $ language:c++ $ result:accepted - time:30 Ms - memory:1060 KB the ****************************************************************/
[JOBDU] topic 1377: Slow variable sequence