hdu 5916 Harmonic Value Description
来源:互联网 发布:手机用数据会出400bad 编辑:程序博客网 时间:2024/05/02 02:31
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].
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 ).
For each test case, there is only one line describing the given integers n and k (
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
24 14 2
Sample Output
Case #1: 4 1 3 2Case #2: 2 4 1 3
构造序列。
一个正常序列相邻两数的gcd()肯定为1.
很重要的一个条件,1<=2k<=n<=10000;
所以,提取出k 和 2k;
但是当k为奇数时。 gcd(k-1,k+1)可能不是1.
所以把1放在 k-1 和 k+1 之间 保证除了 k 可 2k ;其他gcd()都为1。
#include<bits/stdc++.h>using namespace std;int main(){ int T,n,k,ca=1; cin>>T; while(T--) { scanf("%d%d",&n,&k); printf("Case #%d: ",ca++); if(n==1&&k==1) printf("1"); else if(k&1) { printf("%d %d",2*k,k); for(int i=2;i<k;i++) printf(" %d",i); if(k!=1) printf(" 1"); for(int i=k+1;i<2*k;i++) printf(" %d",i); for(int i=2*k+1;i<=n;i++) printf(" %d",i); } else { printf("%d %d",2*k,k); for(int i=1;i<k;i++) printf(" %d",i); for(int i=k+1;i<2*k;i++) printf(" %d",i); for(int i=2*k+1;i<=n;i++) printf(" %d",i); } printf("\n"); } return 0;}
0 0
- HDU 5916 Harmonic Value Description
- hdu 5916 Harmonic Value Description
- hdu 5916 Harmonic Value Description
- HDU 5916 - Harmonic Value Description
- Harmonic Value Description HDU
- HDU 5916 Harmonic Value Description (水题)
- hdu 5916 Harmonic Value Description 构造
- hdu 5916 Harmonic Value Description 构造
- hdu 5916 Harmonic Value Description 最大公约数
- HDU 5916 Harmonic Value Description(规律+构造)
- HDU 5916 Harmonic Value Description (2016-ccpc-长春)
- HDOJ 5916 Harmonic Value Description(脑洞题)
- HDU5916 Harmonic Value Description
- HDU5916-Harmonic Value Description
- HDU5914 Harmonic Value Description
- HDU5916-Harmonic Value Description
- hdu5916 Harmonic Value Description
- HDU 5916 Harmonic Value Description 【构造】(2016中国大学生程序设计竞赛(长春))
- OkHttp源码解析(二)——整体流程(下)
- 【HDU】5796 Magic Number【lca】
- 三种无线传输技术在物联网应用的比较
- OkHttp源码解析(三)——连接池复用
- 实战1 walker登录页面的实现
- hdu 5916 Harmonic Value Description
- OkHttp源码解析(四)——失败重连
- 会场安排问题核心思想与代码实现
- 试试水
- Android 粒子效果
- ThreadPoolExecutor的原理及使用方法
- spoj 375 Query on a tree(树链剖分,边,线段树)
- Esper 视图 Views窗口语法
- 【HDU】5789 Permutation【dp】