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;
}

转载于:https://www.cnblogs.com/mch5201314/p/9873475.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值