[測試題]膜法師


Description

在你的幫助下,膜法師們成功地續走了香港記者。

n 個膜法師各有 ai 的時間能續給長者,但是 n 個膜法師一起續命要考慮效率問題,他們要選出一個數 g 使得每個膜法師續給長者的時間是 g 的倍數,膜法師們有一個能力值 k,每個膜法師能偷偷將不超過 k 的時間偷偷直接續給長者,來使膜法陣發揮更大的威力。由於膜法陣有一定容錯性,能有 f 個膜法師不符合續給長者的時間是 g 的倍數這個要求。

一句話題意:有 n 個數構成的數列 A 元素為 ai,你要構造一個數列 B 元素為 bi 使得滿足bi > 0; ai - k bi ai 使得去除 f 個元素后 bi 的有公約數 g。一個測試點有多組測試數據,當一個測試點的所有測試數據都與標准答案相同時,該測試點得分。

Input

輸入文件名為 mogician.in
第一行,一個整數 T,表示數據組數。
對於下面的每一組數據:
第一行,三個整數 nkf 表示膜法師數量,能力值和容錯值。
第二行, n 個整數 ai,依次表示每個膜法師的時間。

Output

輸出文件名為 mogician.out
T 行,每行升序輸出滿足題意的所有整數 g

Sample Input

1
6 3 1
78 69 55 102 233 666

Sample Output

1 2 3 4 5 6 11

Hint

題解

 1 #include<set>
 2 #include<map>
 3 #include<cmath>
 4 #include<ctime>
 5 #include<queue>
 6 #include<stack>
 7 #include<vector>
 8 #include<cstdio>
 9 #include<string>
10 #include<cstdlib>
11 #include<cstring>
12 #include<iostream>
13 #include<algorithm>
14 #define LL long long
15 #define RE register
16 #define IL inline
17 using namespace std;
18 const int N=2e6;
19 const int INF=~0u>>1;
20 
21 IL int Read()
22 {
23     int sum=0;
24     char c=getchar();
25     while (c<'0'||c>'9') c=getchar();
26     while (c>='0'&&c<='9') sum=sum*10+c-'0',c=getchar();
27     return sum;
28 }
29 IL void put(int d)
30 {
31     if (!d) return;
32     put(d/10);
33     putchar(d%10+'0');
34 }
35 
36 IL int Min(const int &a,const int &b) {return a<b ? a:b;}
37 IL int Max(const int &a,const int &b) {return a>b ? a:b;}
38 
39 int t,n,k,f,maxn;
40 int a[N+5];
41 int s[N+5];
42 
43 int main()
44 {
45     t=Read();
46     while (t--)
47     {
48         n=Read();k=Read();f=Read();
49         maxn=0;
50         memset(s,0,sizeof(s));
51         for (RE int i=1;i<=n;i++) a[i]=Read(),maxn=Max(maxn,a[i]),s[a[i]]++;
52         for (RE int i=1;i<=maxn;i++) s[i]+=s[i-1];
53         for(RE int d=1;d<=maxn;d++)
54             {
55                 int cnt=s[d-1];
56                 for(RE int j=d;cnt<=f&&j+k+1<=maxn;j+=d)
57                     if (j+k<Min(maxn,j+d-1)) cnt+=s[Min(maxn,j+d-1)]-s[j+k];
58                 if (cnt<=f) put(d),putchar(' ');
59             }
60         putchar('\n');
61     }
62     return 0;
63 }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM