日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

【HDU - 5916】Harmonic Value Description (构造,思维,SJ题)

發布時間:2023/12/10 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【HDU - 5916】Harmonic Value Description (构造,思维,SJ题) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題干:

The harmonic value of the permutation?p1,p2,?pnp1,p2,?pn?is?

∑i=1n?1gcd(pi.pi+1)∑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].

Input

The first line contains only one integer T (1≤T≤1001≤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≤100001≤2k≤n≤10000).

Output

For each test case, output one line “Case #x:?p1?p2???pnp1?p2???pn”, where x is the case number (starting from 1) and?p1?p2???pnp1?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

解題報告:

? ? ? 構造。這題顯然不會有統一的規律讓你去找或者暴力求解。所以我們要考慮是不是個Special Judge的題,也就是,我們只需要給出其中的一個答案就可以了。

? ? ? 顯然我們不難發現,最小的∑值,恰好是n-1,也就是說,按照升序排序,每兩個數的gcd都=1,所以他讓求第k小的,也就是我們只需要讓其中一對兒gcd=1的變成=k的就可以了,題目給了一個隱藏的暗示:2*k<=n,所以我們就把2*k 和 k?放在前兩個的位置上,其余的數依舊保證“相鄰的數的gcd=1”即可。于是想到先繼續從k+1開始輸出到2*k-1,然后再輸出1~k-1? 。這樣剛好符合題意。

AC代碼:

#include<bits/stdc++.h> using namespace std;int main(){int t,n,cas=1,k;cin>>t;while(t--){cin>>n>>k;printf("Case #%d: %d %d",cas++,2*k,k);for(int i=k+1;i<=n;i++){if(i==2*k)continue;printf(" %d",i);}for(int i=1;i<=k-1;i++)printf(" %d",i);puts("");}return 0; }

?

總結

以上是生活随笔為你收集整理的【HDU - 5916】Harmonic Value Description (构造,思维,SJ题)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。