题目描述

The harmonic value of the permutation $p_1,p_2,\cdots p_n$ is
$$\sum_{i=1}^{n-1} gcd(p_i.p_{i+1})$$
Mr. Frog is wondering about the permutation whose harmonic value is the strictly k-th smallest among all the permutations of [n].

输入

The first line contains only one integer T ($1\leq T\leq 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\leq 2k \leq n \leq10000$).

输出

For each test case, output one line “Case #x: $p_1\ p_2\ \cdots \ p_n$”, where x is the case number (starting from 1) and $p_1\ p_2\ \cdots \ p_n$ is the answer.

样例输入

2
4 1
4 2

样例输出

Case #1: 4 1 3 2
Case #2: 2 4 1 3
分析:按要求,gcd(i,i+1)=1,gcd(k,2*k)=k。
#include <iostream>
#include <string>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#define range(i,a,b) for(int i=a;i<=b;++i)
#define LL long long
#define rerange(i,a,b) for(int i=a;i>=b;--i)
#define fill(arr,tmp) memset(arr,tmp,sizeof(arr))
using namespace std;
int t;
void init() {
cin>>t;
}
void solve(){
int cas=;
while(t--){
int n,k;
cin>>n>>k;
cout<<"Case #"<<++cas<<": "<<(k<<)<<" "<<k;
range(i,k+,n){
if(i==(k<<))continue;
cout<<" "<<i;
}
range(i,,k-)cout<<" "<<i;
cout<<endl;
}
}
int main() {
init();
solve();
return ;
}

HDU 5916: Harmonic Value Description的更多相关文章

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

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

  2. HDU 5916 Harmonic Value Description (构造)

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

  3. Harmonic Value Description HDU - 5916

    The harmonic value of the permutation p1,p2,⋯pn is ∑i=1n−1gcd(pi.pi+1) Mr. Frog is wondering about t ...

  4. Harmonic Value Description(构造题)

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

  5. 2016 CCPC长春重现赛

    1.2016中国大学生程序设计竞赛(长春)-重现赛 2.总结:会做的太少,应变能力也不行,或者说猜题目的能力不行 02  水 04  HDU 5914  Triangle 1.题意:1~n,n个数,问 ...

  6. 2016CCPC长春 - B/D/F/H/I/J/K - (待补)

    目录: B - Fraction D - Triangle F - Harmonic Value Description H - Sequence I I - Sequence II B题:HDU 5 ...

  7. 数位DP入门之hdu 3652 B-number

    hdu 3652 B-number Problem Description A wqb-number, or B-number for short, is a non-negative integer ...

  8. cdq分治(hdu 5618 Jam's problem again[陌上花开]、CQOI 2011 动态逆序对、hdu 4742 Pinball Game、hdu 4456 Crowd、[HEOI2016/TJOI2016]序列、[NOI2007]货币兑换 )

    hdu 5618 Jam's problem again #include <bits/stdc++.h> #define MAXN 100010 using namespace std; ...

  9. HDU 6787 Chess 2020百度之星 初赛三 T5 题解 dp

    传送门:HDU 6787 Chess Problem Description 你现在有一个棋盘,上面有 n 个格子,格子从左往右,1,-,n 进行标号.你可以在棋盘上放置恰好 m 个传送器,并且对于每 ...

随机推荐

  1. Remote使用出现的问题及解决办法

    最近尝试跟着虫师的OP模式所写的bbs代码,应用自己的项目尝试修改,在第一步Remote启动Firefox上便出错,当前selenium2.53,firefox47.1,selenium server ...

  2. webdriver--定位一组元素+iframe表单切换

    定位一组元素:find_elements,返回的是list,所以可以用列表的索引对列表里的某个元素操作,也可以用for循环访问list,依次操作各元素 driver.find_elements_by_ ...

  3. ASP NET Core ---Automapper

    官方文档:http://docs.automapper.org/en/stable/index.html 一.安装和配置: 二.使用: 1.建立 Profile文件: public class Map ...

  4. CentOS 6.3安装配置LAMP服务器(Linux+Apache+MySQL+PHP5)

    服务器系统环境:CentOS 6.3 客户端系统环境:Windows 7 ultimate(x86)sp1 简体中文旗舰版 ※  本文档描述了如何在Linux服务器配置Apache.Mysql.PHP ...

  5. android ViewGroup getChildDrawingOrder与 isChildrenDrawingOrderEnabled()

    getChildDrawingOrder与 isChildrenDrawingOrderEnabled()是属于ViewGroup的方法.   getChildDrawingOrder 用于 返回当前 ...

  6. PAT 1050 螺旋矩阵

    https://pintia.cn/problem-sets/994805260223102976/problems/994805275146436608 本题要求将给定的 N 个正整数按非递增的顺序 ...

  7. PHP面向对象练习2

    思路:构造函数完成数据库连接,增删改一个方法,查询一条记录一个方法,查询多条一个方法,sql执行失败则返回提示,并交出sql语句方便查错 代码: <?class dbcontroll{ priv ...

  8. 【BestCoder #45】

    用家里的电脑来编程,各种不算 一开始15分钟刷掉T1和T2,然后就永远地卡在了T3... 后来看题解,傻了眼... 它强调的“只有一个答案”我还以为这是在提示我二分答案,于是我一直往权值线段树那个方向 ...

  9. centos7配置环境LNMP

    #yum安装epel-release第三方软件包 yum install epel-release #要验证EPEL仓库是否建立成功 yum repolist xshell访问系统出现中文乱码的解决方 ...

  10. POJ1679 The Unique MST

    Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 26782   Accepted: 9598 Description Give ...