HDU 5916 Harmonic Value Description【构造】【2016中国大学生程序设计竞赛(长春)】
来源:互联网 发布:站群软件 编辑:程序博客网 时间:2024/05/17 08:49
Harmonic Value Description
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 431 Accepted Submission(s): 274
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].
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
Source
2016中国大学生程序设计竞赛(长春)-重现赛
原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=5916
题意:1-n的自然数,让你将其重新排序,使得相邻两个数的GCD之和为K,(K<=n/2)
原数列的GCD之和为n-1。
第一小的肯定是n-1,第二小的肯定是n-2,只需要使得出现相邻的两个数的GCD为2就OK了,以此类推,
因题目中K<=n/2,极限情况就是将所有的偶数放在依次放在前面,奇数依次放到后面即可,
该题有多种答案,满足即可。
AC代码:
#include <iostream>#include <cstring>#include <cstdio>using namespace std;const int maxn=10000+5;bool vis[maxn];int main(){ int T,kase=0; cin>>T; while(T--) { int n,k; cin>>n>>k; memset(vis,false,sizeof(vis)); printf("Case #%d:",++kase); for(int i=1;i<=k;i++) { vis[i*2]=true; } for(int i=1;i<=n;i++) if(vis[i]) cout<<" "<<i; for(int i=1;i<=n;i++) if(!vis[i]) cout<<" "<<i; cout<<endl; } return 0;}
尊重原创,转载请注明出处:http://blog.csdn.net/hurmishine
0 0
- HDU 5916 Harmonic Value Description【构造】【2016中国大学生程序设计竞赛(长春)】
- HDU 5916 Harmonic Value Description 【构造】(2016中国大学生程序设计竞赛(长春))
- HDU 5916 Harmonic Value Description【思维构造题目】(2016中国大学生程序设计竞赛(长春)F题)
- hdu 5916 Harmonic Value Description-思维题-2016中国大学生程序设计竞赛(长春)-重现赛
- HDU Harmonic Value Description 2016中国大学生程序设计竞赛(长春)-重现赛
- HDU 5916 Harmonic Value Description (2016-ccpc-长春)
- HDU 5914 Triangle 【构造】 (2016中国大学生程序设计竞赛(长春))
- hdu 5916 Harmonic Value Description 构造
- hdu 5916 Harmonic Value Description 构造
- HDU Fraction 2016中国大学生程序设计竞赛(长春)-重现赛
- HDU Triangle 2016中国大学生程序设计竞赛(长春)-重现赛
- hdu 5912 Fraction 2016中国大学生程序设计竞赛(长春) 水题
- hdu 5912 Fraction -2016中国大学生程序设计竞赛(长春)
- HDU 5916 Harmonic Value Description(规律+构造)
- HDOJ 5916 Harmonic Value Description 【2016CCPC长春现场赛】数学+构造
- hdu 5916 Harmonic Value Description 2016ACM/CCPC长春赛区现场赛F
- Harmonic Value Description(长春重现赛)
- HDU 5916 Harmonic Value Description
- Hexo博客搭建与优化过程中常见问题及解方案
- Label与ScrollView
- 51nod 1024 矩阵中不重复的元素(数学水题-取对数)
- 【HAOI2008】硬币购物
- 有些段子
- HDU 5916 Harmonic Value Description【构造】【2016中国大学生程序设计竞赛(长春)】
- 字符串翻转算法-JAVA
- typedef常用方法
- EL表达式
- Linux程序设计--线程
- 深刻理解Python中的元类(metaclass)
- 1622-5 孔富晨 总结《2016年10月21日》 【连续第21天总结】
- $.ajax()方法详解
- 接上篇(解决float导致塌陷问题)之clear:both失效