Harmonic Value Description(构造题)
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
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
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(构造题)的更多相关文章
- HDU 5916 Harmonic Value Description (构造)
题意:给你 n 和 m,求一个1-n的排列,使得∑gcd(Ai,Ai+1) 恰为第 m 小. 析:可以想到最小的就是相邻都互质,然后依次,第 m 小就可以有一个是gcd为 k,然后其他的为1喽. 那 ...
- HDU 5916 Harmonic Value Description 【构造】(2016中国大学生程序设计竞赛(长春))
Harmonic Value Description Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Ja ...
- Educational Codeforces Round 7 D. Optimal Number Permutation 构造题
D. Optimal Number Permutation 题目连接: http://www.codeforces.com/contest/622/problem/D Description You ...
- BZOJ 3097: Hash Killer I【构造题,思维题】
3097: Hash Killer I Time Limit: 5 Sec Memory Limit: 128 MBSec Special JudgeSubmit: 963 Solved: 36 ...
- CDOJ 1288 旅游的Final柱 构造题
旅游的Final柱 题目连接: http://acm.uestc.edu.cn/#/problem/show/1288 Description 柱神要去打Final啦~(≧▽≦)/~啦啦啦 柱神来到了 ...
- HDU 5355 Cake (WA后AC代码,具体解析,构造题)
题目链接:http://acm.hdu.edu.cn/showproblem.php? pid=5355 题面: Cake Time Limit: 2000/1000 MS (Java/Others) ...
- cf251.2.C (构造题的技巧)
C. Devu and Partitioning of the Array time limit per test 1 second memory limit per test 256 megabyt ...
- hdu4671 Backup Plan ——构造题
link:http://acm.hdu.edu.cn/showproblem.php?pid=4671 其实是不难的那种构造题,先排第一列,第二列从后往前选. #include <iostrea ...
- Codeforces 482 - Diverse Permutation 构造题
这是一道蛮基础的构造题. - k +(k - 1) -(k - 2) 1 + k , 1 , k , 2, ....... ...
随机推荐
- 初识FASTBuild 一个大幅提升C/C++项目编译速度的分布式编译工具
FASTBuild 是一款高性能.开源的构建系统,支持高度可扩展的编译,缓存和网络分发. 以上是FASTBuild官网对其产品的一句话介绍. FASTBuild 的开源地址:https://githu ...
- 【MyBatis学习02】走进MyBatis的世界
mybatis是个持久层的框架,用来执行数据库操作的,无外乎增删改查,上一节对mybatis有了宏观上的了解后,这一篇博客主要通过一个小示例来入门mybatis,先看一下要写的示例需求: 根据用户id ...
- ZOJ 3827 Information Entropy (2014牡丹江区域赛)
题目链接:ZOJ 3827 Information Entropy 依据题目的公式算吧,那个极限是0 AC代码: #include <stdio.h> #include <strin ...
- Centos系统设置
1.设置中文语言 yum install fonts-chinese vim /etc/sysconfig/i18n LANG="zh_CN.GB18030" LANGUAGE=& ...
- leetcode_Power of Two_easy
Given an integer, write a function to determine if it is a power of two. 题目意思:推断某个数是否是2的幂. 方法:直接进行bi ...
- C++避免内存泄漏的一种技巧
C++ Primer 4th中在section 13.5中的U_Ptr就是一种实用的例子 通过计数的方式,并提供自己的抽象类型的Pointer,从而实现内存管理.在一定的范围内还是非常有效的,比如说在 ...
- 内核交互--procfs
文档介绍:http://lxr.linux.no/linux+v2.6.37/Documentation/filesystems/proc.txt以下内容抄录linux设备驱动开发详解-宋宝华在/pr ...
- Mybatis结果生成键值对
在实际应用中我们经常会遇到这样的情况,需要给下拉框赋值,这个时候就需要键值对了,具体使用方法如下 1,在maper.xml文件中定义结果类型(resultType)定义为hashmap,如下所示 &l ...
- X264参考手册
艺搜简介 基本语法: x264 [options]-o outfile infile 注意与ffmpeg的输入输出文件位置恰好相反: ffmpeg[options][[infile options]- ...
- js实现点击定位最顶端
//------------------------------------点击按钮------------------------------------ <span onClick=&quo ...