Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)

Total Submission(s): 786    Accepted Submission(s): 456
Special Judge

Problem Description

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

∑i=1n−1gcd(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 (1≤T≤100), which indicates the number of test cases.

For each test case, there is only one line describing the given integers n and k (1≤2k≤n≤10000).

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

//题目看上去比较复杂,其实就需要一点点思维,问 1-n n个数,第 k 小的harmonic value的排列是怎样的

题解: 要第 k 大就把前 k 个偶数丢前面去,剩下的不变就好了

 #include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std; int main()
{
int T;
cin>>T;
for (int cnt=;cnt<=T;cnt++)
{
int n ,k;
scanf("%d%d",&n,&k);
printf("Case #%d:",cnt);
for (int i=;i<=k;i++)
printf(" %d",i*);
for (int i=;i<=n;i++)
{
if (i%==&&i<=*k) continue;
printf(" %d",i);
}
printf("\n");
}
return ;
}

Harmonic Value Description(构造题)的更多相关文章

  1. HDU 5916 Harmonic Value Description (构造)

    题意:给你 n 和 m,求一个1-n的排列,使得∑gcd(Ai,Ai+1) 恰为第  m 小. 析:可以想到最小的就是相邻都互质,然后依次,第 m 小就可以有一个是gcd为 k,然后其他的为1喽. 那 ...

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

    Harmonic Value Description Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Ja ...

  3. Educational Codeforces Round 7 D. Optimal Number Permutation 构造题

    D. Optimal Number Permutation 题目连接: http://www.codeforces.com/contest/622/problem/D Description You ...

  4. BZOJ 3097: Hash Killer I【构造题,思维题】

    3097: Hash Killer I Time Limit: 5 Sec  Memory Limit: 128 MBSec  Special JudgeSubmit: 963  Solved: 36 ...

  5. CDOJ 1288 旅游的Final柱 构造题

    旅游的Final柱 题目连接: http://acm.uestc.edu.cn/#/problem/show/1288 Description 柱神要去打Final啦~(≧▽≦)/~啦啦啦 柱神来到了 ...

  6. HDU 5355 Cake (WA后AC代码,具体解析,构造题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php? pid=5355 题面: Cake Time Limit: 2000/1000 MS (Java/Others) ...

  7. cf251.2.C (构造题的技巧)

    C. Devu and Partitioning of the Array time limit per test 1 second memory limit per test 256 megabyt ...

  8. hdu4671 Backup Plan ——构造题

    link:http://acm.hdu.edu.cn/showproblem.php?pid=4671 其实是不难的那种构造题,先排第一列,第二列从后往前选. #include <iostrea ...

  9. Codeforces 482 - Diverse Permutation 构造题

    这是一道蛮基础的构造题. - k         +(k - 1)      -(k - 2) 1 + k ,    1 ,         k ,             2,    ....... ...

随机推荐

  1. 用箭头函数精简Vue 模块

    https://www.zcfy.cc/article/clean-up-your-vue-modules-with-es6-arrow-functions-dotdev 使用箭头函数,this指向v ...

  2. 说说C#的数学类,Math,浮点数(上)

    说说C#的数学类,Math,浮点数 C#语言支持下图所看到的的数值类型,各自是整数,浮点数和小数 可能不是非常清楚,可是细致看看还是能看清楚的. 在一个C#程序中,整数(没有小数点的数)被觉得是一个i ...

  3. linux命令之head、tail命令具体解释

    head 语法 样例 tail 语法 样例 head和tail组合使用方法举例 head 语法 head [-n -k ]... [FILE]... 样例 默认是显示开头前10行. head /etc ...

  4. iDempiere = OSGi + ADempiere 一款ERP&CRM&SCM系统、助力中小企业发展

    怀揣着为中小企业量身定做一整套开源软件解决方案的梦想开始了一个网站的搭建.http://osssme.org/ iDempiere = OSGi + ADempiere 一款ERP&CRM&a ...

  5. Bootstrap-初步学习

    <!DOCTYPE html> <html> <head lang="en"> <meta charset="utf-8&quo ...

  6. C#创建一个Window服务

    Window服务介绍 Microsoft Windows 服务能够创建在它们自己的 Windows 会话中可长时间运行的可执行应用程序.这些服务可以在计算机启动时自动启动,可以暂停和重新启动而且不显示 ...

  7. 转:winform_webApiSelfHost及 OWIN WebAPI Service

    winform_webApiSelfHost 窗本构造函数中添加以下代码: var baseAddress = ConfigurationManager.AppSettings["baseA ...

  8. Linux入门常用指令

    linux获取硬盘和目录大小的命令 df命令 Linux下可以用df命令获取硬盘的使用情况,通过man可以获取df命令的详细情况.df命令经常用的参数为: a:显示全部的档案系统和各分割区的磁盘使用情 ...

  9. jquery的基本api

    本文整理了一些主要的jQuery API,其中包括jQuery 核心函数和方法.jQuery属性参考手册.jQuery CSS操作.jQuery选择器.jQuery文档操作.jQuery筛选操作.jQ ...

  10. MySQL获取Schema表名和字段信息

    MySQL获取Schema表名和字段信息 获取表名 select TABLE_NAME,TABLE_TYPE,ENGINE,TABLE_ROWS,TABLE_COMMENT,CREATE_TIME,U ...