HDU5916

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了HDU5916相关的知识,希望对你有一定的参考价值。

Harmonic Value Description

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 287    Accepted Submission(s): 184
Special Judge


Problem Description

The harmonic value of the permutation p1,p2,?pn is

i=1n1gcd(pi.pi+1)


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
 

 

Source

 
求gcd值第k小的1到n的排列。
 1 //2016.10.08
 2 #include <iostream>
 3 #include <cstdio>
 4 #include <cstring>
 5 
 6 using namespace std;
 7 
 8 int main()
 9 {
10     int T, n, k, kase = 0;
11     scanf("%d", &T);
12     while(T--)
13     {
14         int tmp = -1;
15         scanf("%d%d", &n, &k);
16         printf("Case #%d:", ++kase);
17         if(k == 1){
18             for(int i = 1; i <= n; i++)
19                   printf(" %d", i);
20         }else{
21             if(k&1){
22                 printf(" %d %d", 2*k, k);
23                 for(int i = 2; i <= n; i++)
24                 {
25                     if(i == 2*k)continue;
26                     if(i == k)printf(" 1");
27                     else printf(" %d", i);
28                 }
29             }else{
30                 printf(" %d %d", 2*k, k);
31                 for(int i = 1; i <= n; i++)
32                 {
33                     if(i == k || i == 2*k)continue;
34                     else printf(" %d", i);
35                 }
36             }
37         }
38         printf("\n");
39     }
40 
41     return 0;
42 }

 

以上是关于HDU5916的主要内容,如果未能解决你的问题,请参考以下文章

HDU 5916 Harmonic Value Description 构造(2016中国大学生程序设计竞赛(长春))

CCPC2016长春F (hdu 5916 Harmonic Value Description)

[DFS]JZOJ 5916 flow

解题报告Leecode 5916. 转化数字的最小运算数

5916. 转化数字的最小运算数

HDU4057 Rescue the Rabbit(AC自动机+状压DP)