zoukankan      html  css  js  c++  java
  • 【CF1043B】Lost Array(枚举)

    题意:给定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 }
  • 相关阅读:
    AppiumForWin安装
    AppiumForMac安装2
    AppiumForMac安装1
    在MacOS安装puppeteer
    puppeteerExamples
    为什么总有target=_blank?
    Canvas 与 SVG
    HTML5+CSS3兼容收藏夹
    html 5 读取本地文件API
    【Web Audio API】 — 那些年的 web audio
  • 原文地址:https://www.cnblogs.com/myx12345/p/9872124.html
Copyright © 2011-2022 走看看