zoukankan      html  css  js  c++  java
  • Bzoj2081 [Poi2010]Beads

    Time Limit: 10 Sec  Memory Limit: 259 MB
    Submit: 698  Solved: 249

    Description

    Zxl有一次决定制造一条项链,她以非常便宜的价格买了一长条鲜艳的珊瑚珠子,她现在也有一个机器,能把这条珠子切成很多块(子串),每块有k(k>0)个珠子,如果这条珠子的长度不是k的倍数,最后一块小于k的就不要拉(nc真浪费),保证珠子的长度为正整数。 Zxl喜欢多样的项链,为她应该怎样选择数字k来尽可能得到更多的不同的子串感到好奇,子串都是可以反转的,换句话说,子串(1,2,3)和(3,2,1)是一样的。写一个程序,为Zxl决定最适合的k从而获得最多不同的子串。 例如:这一串珠子是: (1,1,1,2,2,2,3,3,3,1,2,3,3,1,2,2,1,3,3,2,1), k=1的时候,我们得到3个不同的子串: (1),(2),(3) k=2的时候,我们得到6个不同的子串: (1,1),(1,2),(2,2),(3,3),(3,1),(2,3) k=3的时候,我们得到5个不同的子串: (1,1,1),(2,2,2),(3,3,3),(1,2,3),(3,1,2) k=4的时候,我们得到5个不同的子串: (1,1,1,2),(2,2,3,3),(3,1,2,3),(3,1,2,2),(1,3,3,2)

    Input

    共有两行,第一行一个整数n代表珠子的长度,(n<=200000),第二行是由空格分开的颜色ai(1<=ai<=n)。

    Output

    也有两行,第一行两个整数,第一个整数代表能获得的最大不同的子串个数,第二个整数代表能获得最大值的k的个数,第二行输出所有的k(中间有空格)。

    Sample Input

    21
    1 1 1 2 2 2 3 3 3 1 2 3 3 1 2 2 1 3 3 2 1

    Sample Output

    6 1
    2

    HINT

     

    Source

    扫描 HASH

    谢天谢地是链不是环。

    既然切完的边角料都不要了,我们可以直接枚举一刀切多长,统计答案即可。

    需要预处理正反hash来判重

     1 #include<iostream>
     2 #include<cstdio>
     3 #include<algorithm>
     4 #include<cmath>
     5 #include<map>
     6 #include<vector>
     7 #define LL long long
     8 #define LU unsigned long long
     9 using namespace std;
    10 const int mxn=200010;
    11 int read(){
    12     int x=0,f=1;char ch=getchar();
    13     while(ch<'0' || ch>'9'){if(ch=='-')f=-f;ch=getchar();}
    14     while(ch>='0' && ch<='9'){x=x*10-'0'+ch;ch=getchar();}
    15     return x*f;
    16 }
    17 int n;
    18 int a[mxn];
    19 LU pw[mxn];
    20 LU L[mxn],R[mxn];
    21 int ans=0;
    22 map<LU,int>mp;
    23 vector<int>ve;
    24 void solve(int lim){
    25     mp.clear();
    26     int res=0;
    27     for(int i=lim;i<=n;i+=lim){
    28         LU tmp=L[i]-L[i-lim]*pw[lim];
    29         if(!mp.count(tmp)){
    30             res++;
    31             LU tmpR=R[i-lim+1]-R[i+1]*pw[lim];
    32             mp[tmp]++;mp[tmpR]++;
    33         }
    34     }
    35     if(res>ans){
    36         ans=res;
    37         ve.clear();ve.push_back(lim);
    38     }
    39     else if(res==ans) ve.push_back(lim);
    40     return;
    41 }
    42 int main(){
    43     int i,j;
    44     n=read();
    45     pw[0]=1;
    46     for(i=1;i<=n;i++)pw[i]=pw[i-1]*251257;
    47     for(i=1;i<=n;i++)a[i]=read();
    48     for(i=1;i<=n;i++)L[i]=L[i-1]*pw[1]+a[i];
    49     for(i=n;i;i--)R[i]=R[i+1]*pw[1]+a[i];
    50     for(i=1;i<=n;i++)
    51         solve(i);
    52     printf("%d %d
    ",ans,ve.size());
    53     for(i=0;i<ve.size();i++){
    54         printf("%d",ve[i]);
    55         if(i<ve.size()-1)printf(" ");
    56     }
    57     
    58     return 0;
    59 }
  • 相关阅读:
    小白日记41:kali渗透测试之Web渗透-SQL手工注入(三)-猜测列名、表名、库名、字段内容,数据库写入
    Python实现百度贴吧自动顶贴机
    回文自动机简述
    计算几何基本知识整理
    考试题Speed
    [ZOJ 2112] [lg2617] Dynamic Rankings
    后缀数组(Suffix Arrary)
    莫比乌斯函数与莫比乌斯反演
    题解 洛谷 P3369 【【模板】普通平衡树】
    EXCRT(扩展中国剩余定理)
  • 原文地址:https://www.cnblogs.com/SilverNebula/p/7028005.html
Copyright © 2011-2022 走看看