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, ....... ...
随机推荐
- Charles 抓HTTPS包报以下错误:
1.You may need to configure your browser or application to trust the Charles Root Certificate. See S ...
- GCD编程-串行队列与并发队列
接着上面的GCD封装,以下进行列子验证 1.导入GCD.h 2.创一个串行队列: - (void)serailQueue{ //创建出队列 GCDQueue *queue = [[GCDQueue ...
- Linux信号(signal) 机制分析(转)
[摘要]本文分析了Linux内核对于信号的实现机制和应用层的相关处理.首先介绍了软中断信号的本质及信号的两种不同分类方法尤其是不可靠信号的原理.接着分析了内核对于信号的处理流程包括信号的触发/注册/执 ...
- strults2标签s:set的用法
struts2标签<s:set></s:set>的用法.原理 http://liuna718-163-com.iteye.com/blog/1124654 我的例子: ...
- 非常酷的 Javascript 简单调试工具Blackbird
Blackbird 是一个开源的 Javascript 调试工具,默认提供一种非常酷的方式展现 Javascript 调试信息,如下图,效果如何呢? 在我们的日常的学习或工作中,经常都会接触到 Jav ...
- TortoiseSVN客户端使用方法
SVN对于程序开发来说是非常重要的东西,它是非常不错的版本管理工具,下面介绍一下TortoiseSVN客户端的使用方法. 工具/原料 TortoiseSVN 方法/步骤 如果没有TortoiseS ...
- jQuery读取json文件
转 http://www.jb51.net/article/36678.htm 1.userInfo.html <!DOCTYPE html PUBLIC "-//W3C//DTD X ...
- javascript消息框
JavaScript有三种消息框: 警告框:alert() alert("我是警告框!!") 确认框:confirm() function show_confirm() { var ...
- Linux虚拟机Centos 设置固定的静态IP
经过两天的研究(研究到深夜1点),百度了很多文章与加了几个linux的群,终于得到一种方式是可以正常设置静态IP且正常的ssh连接的方式. 第一种方式:NAT模式 参考文章 -- 虚拟机中的CentO ...
- Android Studio--NDK编译C代码为.so文件,JNI调用
前言: 从Android Studio开始,就支持jni和.so库调用了. 环境: Windows 7+Android Studio2.1.2+NDK版本:android-ndk-r10e 准备工作: ...