Problem Description
The harmonic value of the permutation n is
HDU 5916 Harmonic Value Description

 


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 (10000).
 

 

Output
For each test case, output one line “Case #x: n 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,求出一个序列,使得他的HDU 5916 Harmonic Value Description和是第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('\n');
25     }
26     return 0;
27 }

 

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-07
  • 2021-08-07
  • 2021-07-03
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-11-18
  • 2021-07-13
  • 2021-12-23
  • 2021-06-29
  • 2022-12-23
相关资源
相似解决方案