码迷,mamicode.com
首页 > 其他好文 > 详细

HDU 5916 Harmonic Value Description 【构造】(2016中国大学生程序设计竞赛(长春))

时间:2016-10-04 14:04:27      阅读:337      评论:0      收藏:0      [点我收藏+]

标签:

 

Harmonic Value Description

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 0    Accepted Submission(s): 0
Special Judge


Problem Description
The harmonic value of the permutation p1,p2,?pn is
i=1n1gcd(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].
 

 

Input
The first line contains only one integer T (1T100), which indicates the number of test cases.

For each test case, there is only one line describing the given integers n and k (12kn10000).
 

 

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
 

 

Statistic | Submit | Clarifications | Back

 

 

题目链接:

  http://acm.hdu.edu.cn/showproblem.php?pid=5916

题目大意:

  给你N和K(1<=K<2K<=2N),求一个1~2N的排列,使得∑gcd(Ai,Ai+1)恰为第K小(等视为相同小)。

题目思路:

  【构造】

  这题一看2K<=2N,可能就是构造题。如果1,2,3...2N排列的话∑gcd(Ai,Ai+1)为第1小。

  若要∑gcd(Ai,Ai+1)=K,只需要将2K和K提出来,将2K放在开头,K放在第二个,接下来只要满足相邻两个数仍然相差1即可。

  只要将K-1~1接在K后面,把K+1~2N接在1后面,去掉2K即可。(2K-1,2K+1为奇数,gcd=1)

 

技术分享
 1 //
 2 //by coolxxx
 3 //#include<bits/stdc++.h>
 4 #include<iostream>
 5 #include<algorithm>
 6 #include<string>
 7 #include<iomanip>
 8 #include<map>
 9 #include<stack>
10 #include<queue>
11 #include<set>
12 #include<bitset>
13 #include<memory.h>
14 #include<time.h>
15 #include<stdio.h>
16 #include<stdlib.h>
17 #include<string.h>
18 //#include<stdbool.h>
19 #include<math.h>
20 #define min(a,b) ((a)<(b)?(a):(b))
21 #define max(a,b) ((a)>(b)?(a):(b))
22 #define abs(a) ((a)>0?(a):(-(a)))
23 #define lowbit(a) (a&(-a))
24 #define sqr(a) ((a)*(a))
25 #define swap(a,b) ((a)^=(b),(b)^=(a),(a)^=(b))
26 #define mem(a,b) memset(a,b,sizeof(a))
27 #define eps (1e-10)
28 #define J 10000
29 #define mod 1000000007
30 #define MAX 0x7f7f7f7f
31 #define PI 3.14159265358979323
32 #pragma comment(linker,"/STACK:1024000000,1024000000")
33 #define N 104
34 using namespace std;
35 typedef long long LL;
36 double anss;
37 LL aans,sum;
38 int cas,cass;
39 int n,m,lll,ans;
40 int main()
41 {
42     #ifndef ONLINE_JUDGEW
43 //    freopen("1.txt","r",stdin);
44 //    freopen("2.txt","w",stdout);
45     #endif
46     int i,j,k;
47 //    init();
48 //    for(scanf("%d",&cass);cass;cass--)
49     for(scanf("%d",&cas),cass=1;cass<=cas;cass++)
50 //    while(~scanf("%s",s))
51 //    while(~scanf("%d",&n))
52     {
53         scanf("%d%d",&n,&m);
54         printf("Case #%d: ",cass);
55         printf("%d %d",m+m,m);
56         for(i=m-1;i;i--)printf(" %d",i);
57         for(i=m+1;i<=n;i++)
58             if(i!=m+m)printf(" %d",i);
59         puts("");
60     }
61     return 0;
62 }
63 /*
64 //
65 
66 //
67 */
View Code

 

HDU 5916 Harmonic Value Description 【构造】(2016中国大学生程序设计竞赛(长春))

标签:

原文地址:http://www.cnblogs.com/Coolxxx/p/5930225.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!