Harmonic Value Description

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 0    Accepted Submission(s): 0
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
 

Statistic | Submit | Clarifications | Back

题目链接:

  http://acm.hdu.edu.cn/showproblem.php?pid=5916

题目大意:

  给你N和K(1<=K<2K<=2N),求一个1~2N的排列,使得∑gcd(Ai,Ai+1)恰为第K小(等视为相同小)。

题目思路:

  【构造】

  这题一看2K<=2N,可能就是构造题。如果1,2,3...2N排列的话∑gcd(Ai,Ai+1)为第1小。

  若要∑gcd(Ai,Ai+1)=K,只需要将2K和K提出来,将2K放在开头,K放在第二个,接下来只要满足相邻两个数仍然相差1即可。

  只要将K-1~1接在K后面,把K+1~2N接在1后面,去掉2K即可。(2K-1,2K+1为奇数,gcd=1)

 //
//by coolxxx
//#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<iomanip>
#include<map>
#include<stack>
#include<queue>
#include<set>
#include<bitset>
#include<memory.h>
#include<time.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
//#include<stdbool.h>
#include<math.h>
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define abs(a) ((a)>0?(a):(-(a)))
#define lowbit(a) (a&(-a))
#define sqr(a) ((a)*(a))
#define swap(a,b) ((a)^=(b),(b)^=(a),(a)^=(b))
#define mem(a,b) memset(a,b,sizeof(a))
#define eps (1e-10)
#define J 10000
#define mod 1000000007
#define MAX 0x7f7f7f7f
#define PI 3.14159265358979323
#pragma comment(linker,"/STACK:1024000000,1024000000")
#define N 104
using namespace std;
typedef long long LL;
double anss;
LL aans,sum;
int cas,cass;
int n,m,lll,ans;
int main()
{
#ifndef ONLINE_JUDGEW
// freopen("1.txt","r",stdin);
// freopen("2.txt","w",stdout);
#endif
int i,j,k;
// init();
// for(scanf("%d",&cass);cass;cass--)
for(scanf("%d",&cas),cass=;cass<=cas;cass++)
// while(~scanf("%s",s))
// while(~scanf("%d",&n))
{
scanf("%d%d",&n,&m);
printf("Case #%d: ",cass);
printf("%d %d",m+m,m);
for(i=m-;i;i--)printf(" %d",i);
for(i=m+;i<=n;i++)
if(i!=m+m)printf(" %d",i);
puts("");
}
return ;
}
/*
// //
*/

HDU 5916 Harmonic Value Description 【构造】(2016中国大学生程序设计竞赛(长春))的更多相关文章

  1. HDU 5912 Fraction 【模拟】 (2016中国大学生程序设计竞赛(长春))

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

  2. HDU 5914 Triangle 【构造】 (2016中国大学生程序设计竞赛(长春))

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

  3. HDU 5920 Ugly Problem 【模拟】 (2016中国大学生程序设计竞赛(长春))

    Ugly Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Tota ...

  4. 2016中国大学生程序设计竞赛 - 网络选拔赛 C. Magic boy Bi Luo with his excited tree

    Magic boy Bi Luo with his excited tree Problem Description Bi Luo is a magic boy, he also has a migi ...

  5. HDU 6156 - Palindrome Function [ 数位DP ] | 2017 中国大学生程序设计竞赛 - 网络选拔赛

    普通的数位DP计算回文串个数 /* HDU 6156 - Palindrome Function [ 数位DP ] | 2017 中国大学生程序设计竞赛 - 网络选拔赛 2-36进制下回文串个数 */ ...

  6. HDU 6154 CaoHaha's staff(2017中国大学生程序设计竞赛 - 网络选拔赛)

    题目代号:HDU 6154 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6154 CaoHaha's staff Time Limit: 2000/1 ...

  7. HDU 5916 Harmonic Value Description (构造)

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

  8. 2016中国大学生程序设计竞赛(长春)-重现赛 1010Ugly Problem 回文数 模拟

    Ugly Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Tota ...

  9. 2016中国大学生程序设计竞赛 - 网络选拔赛 1004 Danganronpa

    Problem Description Chisa Yukizome works as a teacher in the school. She prepares many gifts, which ...

随机推荐

  1. MyTask4

    最近稍微做了点修改,把几处bug修复了下,另外新增了授权码功能和数据缓冲功能 先看看效果图 1. 如果要把软件做的高大上一些,你可以加一个授权验证,授权码以字符串形式存放在程序里面,当然你也可以另外开 ...

  2. mysql锁表和解锁语句分享

    对于MySQL来说,有三种锁的级别:页级.表级.行级   页级的典型代表引擎为BDB.  表级的典型代表引擎为MyISAM,MEMORY以及很久以前的ISAM.  行级的典型代表引擎为INNODB.  ...

  3. jQuery Ajax 实例 全解析

     jQuery确实是一个挺好的轻量级的JS框架,能帮助我们快速的开发JS应用,并在一定程度上改变了我们写JavaScript代码的习惯. 废话少说,直接进入正题,我们先来看一些简单的方法,这些方法都是 ...

  4. volatile用处说明

      在JDK1.2之前,Java的内存模型实现总是从主存(即共享内存)读取变量,是不需要进行特别的注意的.而随着JVM的成熟和优化,现在在多线程环境下volatile关键字的使用变得非常重要. 在当前 ...

  5. struts启动报错Javassist library is missing

    很久不用struts2,最近在配置的时候,启动服务器报错 Caused by: java.lang.ExceptionInInitializerError at com.opensymphony.xw ...

  6. DataGrid列的合并

    /// <summary> /// DataGrid列的合并 /// 注意:1.DataGrid在绑定的时候进行分组和排序,才能让相同的行放在一起 /// 2.方法应用的时机,应该在Dat ...

  7. 平衡搜索树(三) B-Tree

    B树的简介 B 树是为了磁盘或其它存储设备而设计的一种多叉平衡查找树.与红黑树很相似,但在降低磁盘I/0操作方面要更好一些(树的深度较低).许多数据库系统都一般使用B树或者B树的各种变形结构.B树与红 ...

  8. 分享一个自己写的基于TP的关系模型(2)

    1.增加多对多关系的处理 /** * 定义关系 * @return array */ public function test4(){ //参数说明 //关联的模型 //主表关联字段 //关联中间表 ...

  9. [设计模式]解释器(Interpreter)之大胆向MM示爱吧

    为方便读者,本文已添加至索引: 设计模式 学习笔记索引 写在前面 “我刚写了个小程序,需要你来参与下.”我把MM叫到我的电脑旁,“来把下面这条命令打进去,这是个练习打(Pian)符(ni)号(de)的 ...

  10. js获取天气

    我们经常看到有的网站显示天气信息,它是怎么做出来的呢?今天就来分享一些关于js调用天气API的几种做法. 网上也能找到很多种方法,但是一般都是免费的不好用,好用的不免费. 以前用过新浪的天气api,查 ...