题意:给定n与数组a,求所有的k使得存在x数组能按以下规则构造出a
n<=1e3,a[i]<=1e6
思路:
1 #include<cstdio> 2 #include<cstring> 3 #include<string> 4 #include<cmath> 5 #include<iostream> 6 #include<algorithm> 7 #include<map> 8 #include<queue> 9 #include<vector> 10 #include<ctime> 11 using namespace std; 12 typedef long long ll; 13 typedef unsigned int uint; 14 typedef unsigned long long ull; 15 typedef pair<int,int> PII; 16 typedef vector<int> VI; 17 #define fi first 18 #define se second 19 #define MP make_pair 20 #define N 210000 21 #define M 130 22 #define MOD 1000000007 23 #define eps 1e-8 24 #define pi acos(-1) 25 #define oo 1000000000 26 27 int a[N],x[N],c[N]; 28 29 int main() 30 { 31 int n; 32 scanf("%d",&n); 33 a[0]=0; 34 for(int i=1;i<=n;i++) scanf("%d",&a[i]); 35 36 int ans=0; 37 for(int k=1;k<=n;k++) 38 { 39 int flag=1; 40 for(int j=0;j<=k;j++) x[j]=oo; 41 x[0]=a[1]; 42 for(int j=2;j<=n;j++) 43 { 44 if(x[(j-1)%k]!=oo&&x[(j-1)%k]!=a[j]-a[j-1]){flag=0; break;} 45 x[(j-1)%k]=a[j]-a[j-1]; 46 } 47 if(flag) c[++ans]=k; 48 } 49 printf("%d ",ans); 50 for(int i=1;i<=ans-1;i++) printf("%d ",c[i]); 51 printf("%d",c[ans]); 52 return 0; 53 }