Construction Codeforces 483C Diverse permutation

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.