Topic Portal
1 /*2 Construction: First choose a good k different values, from 1 to K, according to the requirements of the numbers put, the rest of the casual put. Because it is the absolute difference, starting from n one,3 This guarantees that the boundary is not exceeded and that the remaining number is adjacent to the absolute difference >k4 */5 /************************************************6 Author:running_time7 Created time:2015-8-2 9:20:018 File name:b.cpp9 *************************************************/Ten One#include <cstdio> A#include <algorithm> -#include <iostream> -#include <sstream> the#include <cstring> -#include <cmath> -#include <string> -#include <vector> +#include <queue> -#include <deque> +#include <stack> A#include <list> at#include <map> -#include <Set> -#include <bitset> -#include <cstdlib> -#include <ctime> - using namespacestd; in -typedefLong Longll; to Const intMAXN = 1e5 +Ten; + Const intINF =0x3f3f3f3f; - Const intMOD = 1e9 +7; the BOOLVIS[MAXN]; * intA[MAXN]; $ Panax Notoginseng intMainvoid) {//codeforces 483C Diverse permutation - intN, K; the while(SCANF ("%d%d", &n, &k) = =2) { + if(k = =1) { A for(intI=1; i<=n; ++i) { theprintf ("%d%c", I, (i==n)?'\ n':' '); + } - Continue; $ } $memset (Vis,false,sizeof(Vis)); - intj =1; a[0] = N; vis[a[0]] =true;BOOLFlag =false; - for(intI=k; i>=1; --i) { the if(flag) { -A[J] = a[j-1] + i; VIS[A[J]] =true; ++j; Flag =!Flag;Wuyi } the Else { -A[J] = a[j-1]-I; VIS[A[J]] =true; j + +; Flag =!Flag; Wu } - } About intp =N; $ for(intI=j; i<n; ++i) { - for(inti=2; k>=1; --k) { - if(!Vis[k]) { -A[i] = k; VIS[K] =true; p = k; Break; A } + } the } - for(intI=0; i<n; ++i) { $printf ("%d%c", A[i], (i==n-1) ?'\ n':' '); the } the } the the return 0; -}
Construction Codeforces 483C Diverse permutation