B. Lost Array

链接

[http://codeforces.com/contest/1043/problem/B]

题意

自己点开链接看

分析

1到n枚举某个值,判断是否满足并统计
判断方法:假设x序列成立,那么后面就看只需推a[h]==(a[(h-1)%k+1]-a[(h-1)%k]+a[h-1])是否可以进行到最后一个an

代码

#include<bits/stdc++.h>
using namespace std;
#define ll long long

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n,i;
	int a[1010],b[1010];
	//freopen("in.txt","r",stdin);
	while(cin>>n){
		a[0]=0;
		for(i=1;i<=n;i++)
		cin>>a[i];
		int j=0,h,k;
		for(k=1;k<=n;k++){
			for(h=k+1;h<=n;h++)
			{
				if(a[h]!=(a[(h-1)%k+1]-a[(h-1)%k]+a[h-1])) break;
			}
			if(h==n+1) b[j++]=k;
		}
		cout<<j<<endl;
		for(i=0;i<j;i++)
		cout<<b[i]<<' ';
		cout<<endl;
	}
	return 0;
}
posted @ 2018-10-29 21:37  ChunhaoMo  阅读(131)  评论(0)    收藏  举报