HDU 5916 Harmonic Value Description【构造】【2016中国大学生程序设计竞赛(长春)】
2016-10-21 22:27
411 查看
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
.
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
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
相关文章推荐
- 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-长春)
- HDOJ 5916 Harmonic Value Description 【2016CCPC长春现场赛】数学+构造
- hdu 5916 Harmonic Value Description 构造
- HDU 5916 Harmonic Value Description (构造)
- HDU 5914 Triangle 【构造】 (2016中国大学生程序设计竞赛(长春))
- HDU 5916 Harmonic Value Description(规律+构造)
- hdu 5916 Harmonic Value Description 构造
- Harmonic Value Description HDU - 5916 构造
- hdu 5916 Harmonic Value Description 2016ACM/CCPC长春赛区现场赛F
- HDU 5914 Triangle 【构造】 (2016中国大学生程序设计竞赛(长春))
- HDU 5912 【模拟,类连分数的计算】【2016中国大学生程序设计竞赛(长春)】
- hdu 5912 Fraction 2016中国大学生程序设计竞赛(长春) 水题
- HDU 5920 Ugly Problem 【模拟】 (2016中国大学生程序设计竞赛(长春))
- HDU 5912 Fraction 【模拟】 (2016中国大学生程序设计竞赛(长春))
- HDU 5916 - Harmonic Value Description