zoukankan      html  css  js  c++  java
  • HDU 5916 Harmonic Value Description

    Problem Description
    The harmonic value of the permutation p1,p2,pn is

    Mr. Frog is wondering about the permutation whose harmonic value is the strictly k-th smallest among all the permutations of [n].
     
    Input
    The first line contains only one integer T (1T100), which indicates the number of test cases.

    For each test case, there is only one line describing the given integers n and k (12kn10000).
     
    Output
    For each test case, output one line “Case #x: p1 p2  pn”, where x is the case number (starting from 1) and p1 p2  pn is the answer.
     
    Sample Input
    2
    4 1
    4 2
     
    Sample Output
    Case #1: 4 1 3 2
    Case #2: 2 4 1 3
     
     
     题目大意:给定一个数n,k,求出一个序列,使得他的和是第k小的(序列为1-n)

    思路: 找出规律即可,当k=1时,直接按顺序输出1-n;k>1时 讲前2*k个数中的偶数和奇数分别放在一起,最后再将2*k+1 --- n 顺序输出即可

     1 #include<iostream>
     2 #include<algorithm>
     3 #include<cstdio>
     4 
     5 using namespace std;
     6 int T,n,k;
     7 int main()
     8 {
     9     scanf("%d",&T);
    10     for(int t=1;t<=T;t++){
    11         scanf("%d%d",&n,&k);
    12         printf("Case #%d:",t);
    13         if(k>1){
    14             for(int i=2;i<=2*k;i+=2)
    15                 printf(" %d",i);
    16             for(int i=1;i<2*k;i+=2)
    17                 printf(" %d",i);
    18             for(int i=2*k+1;i<=n;i++)
    19                 printf(" %d",i);
    20         }else{
    21             for(int i=1;i<=n;i++)
    22                 printf(" %d",i);
    23         }
    24         putchar('
    ');
    25     }
    26     return 0;
    27 }
  • 相关阅读:
    Android消息的提示,Toast吐司方式
    Java内部类
    Android环境配置及运行helloWord案例
    翻译Android API Guides: App Manifest
    Android Configuration介绍 (未完成)
    jquery之效果操作
    jquery之属性操作
    JQuery之dom文档操作
    jQuery之css操作
    jQuery选择器的优点
  • 原文地址:https://www.cnblogs.com/wangrunhu/p/9614914.html
Copyright © 2011-2022 走看看