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, ....... ...
随机推荐
- odoo报表条码无法显示解决
当服务器为Linux(Ubuntu)时,ODOO打印的报表上是有条码的,却显示空白框框. 问题在于服务器上没有安装条码的字体,reportlab渲染条码图形失败,导致显示不正常. 将附件中的字体下载, ...
- mongoDB group命令详解
http://heipark.iteye.com/blog/1167948 http://rjhym.iteye.com/blog/1224200 http://blog.163.com/ ...
- mongoDB id 导出,dump,sed,count,mysql import等用法示例
#count collectiondb.news.count({"lpublishtime":{"$gte":1358697600000}}); #mongo导 ...
- php中利用reset,current,next和each,list来遍历数组
1.利用for循环以及reset,current,next来遍历数组: $nums = array(11,22,33,44,55,66,77,88); for(reset($nums);current ...
- Windows RabbitMQ 添加用户、设置角色和权限 (包含无法添加的错误处理)
添加账号密码 rabbitmqctl.bat add_user test 123456 添加角色 rabbitmqctl.bat set_user_tags test administrator 授权 ...
- 自己动手一步一步安装hadoop(含编译hadoop的native本地包)
近期项目须要用到hadoop.边学习边应用,第一步无疑是安装hadoop.我安装的是hadoop-2.4.1.以下是具体步骤,做备忘以后查看 一.下载依赖软件 1.java hadoop官网说明仅仅支 ...
- 【Android】 给我一个Path,还你一个酷炫动画
本篇文章已授权微信公众号 hongyangAndroid (鸿洋)独家公布 转载请标明出处: http://blog.csdn.net/zxt0601/article/details/53040506 ...
- C++语言基础(2)-new和delete操作符
在C语言中,动态分配内存用 malloc() 函数,释放内存用 free() 函数.如下所示: ); //分配10个int型的内存空间 free(p); //释放内存 在C++中,这两个函数仍然可以使 ...
- 121. Best Time to Buy and Sell Stock【easy】
121. Best Time to Buy and Sell Stock[easy] Say you have an array for which the ith element is the pr ...
- 125. Valid Palindrome【easy】
125. Valid Palindrome[easy] Given a string, determine if it is a palindrome, considering only alphan ...