传送门

Description

Let S be a number string, and occ(S,x) means the times that number x occurs in S.
i.e. S=(1,2,2,1,3),occ(S,1)=2,occ(S,2)=2,occ(S,3)=1.
String u,w are matched if for each number i, occ(u,i)=occ(w,i) always holds.
i.e. (1,2,2,1,3)≈(1,3,2,1,2).
Let S be a string. An integer k is a full Abelian period of S if S can be partitioned into several continous substrings of length k, and all
of these substrings are matched with each other.
Now given a string S, please
find all of the numbers k that k is a full Abelian period of S.

Input

The first line of the input contains an integer T(1≤T≤10), denoting the number of test cases.
In each test case, the first line of the input contains an integer n(n≤100000),
denoting the length of the string.
The second line of the input contains n integers S1,S2,S3,...,Sn(1≤Si≤n), denoting the elements of the string.

Output

For each test case, print a line with several integers, denoting all of the number k. You should print them in increasing order.

Sample Input

2 6 5 4 4 4 5 4 8 6 5 6 5 6 5 5 6

Sample Output

3 6 2 4 8

思路

题意:将一个数字串分成长度为k的几个连续区间,如果每个区间内各个元素出现的次数相同,则称k为一个阿贝尔周期,从小到大打印所有阿贝尔周期

可以知道,k必然是n的约数,因此统计每个数出现的次数,求出这些次数的最大公约数,枚举这个最大公约数的约数x,即为可分为的m段,k值即为N/x

#include<bits/stdc++.h>
using namespace std;
const int maxn = 100005;

int gcd(int a,int b)
{
    return b?gcd(b,a%b):a;
}

int main()
{
    int T;
    scanf("%d",&T);
    while (T--)
    {
        int N,a[maxn],cnt[maxn];
        memset(cnt,0,sizeof(cnt));
        scanf("%d",&N);
        for (int i = 0;i < N;i++)
        {
            scanf("%d",&a[i]);
            cnt[a[i]]++;
        }
        int tmp = cnt[1];
        for (int i = 2;i < maxn;i++)    tmp = gcd(tmp,cnt[i]);
        bool first = true;
        for (int i = tmp;i >= 1;i--)
        {
            if (tmp % i == 0)
            {
                first?printf("%d",N/i):printf(" %d",N/i);
                first = false;
            }
        }
        printf("\n");
    }
    return 0;
}

  

 

HDU 5908 Abelian Period(暴力+想法题)的更多相关文章

  1. HDU 5908 Abelian Period 暴力

    Abelian Period 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5908 Description Let S be a number st ...

  2. HDU 5908 Abelian Period (BestCoder Round #88 模拟+暴力)

    HDU 5908 Abelian Period (BestCoder Round #88 模拟+暴力) 题目链接http://acm.hdu.edu.cn/showproblem.php?pid=59 ...

  3. HDU 5908 Abelian Period 可以直接用multiset

    http://acm.hdu.edu.cn/showproblem.php?pid=5908 要求把数组分成k组使得每组中的元素出现次数相同 就是分成k个集合,那么直接用multiset判定就可以 有 ...

  4. HDU - 5806 NanoApe Loves Sequence Ⅱ 想法题

    http://acm.hdu.edu.cn/showproblem.php?pid=5806 题意:给你一个n元素序列,求第k大的数大于等于m的子序列的个数. 题解:题目要求很奇怪,很多头绪但写不出, ...

  5. HDU 4972 Bisharp and Charizard 想法题

    Bisharp and Charizard Time Limit: 1 Sec  Memory Limit: 256 MB Description Dragon is watching NBA. He ...

  6. HDU - 5969 最大的位或 想法题

    http://acm.hdu.edu.cn/showproblem.php?pid=5969 (合肥)区域赛签到题...orz 题意:给你l,r,求x|y的max,x,y满足l<=x<=y ...

  7. HDU 5632 Rikka with Array [想法题]

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5632 ------------------------------------------------ ...

  8. HDU5908 Abelian Period 暴力

    题目大意:将一个数组分成长度为k的几个连续区间,如果每个区间内各个元素出现的次数相同,则称k为一个阿贝尔周期,从小到大打印所有阿贝尔周期,数据间加空格. 题目思路:map+暴力 #include< ...

  9. HDU 4638 树状数组 想法题

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4638 解题思路: 题意为询问一段区间里的数能组成多少段连续的数.先考虑从左往右一个数一个数添加,考虑当 ...

随机推荐

  1. Theano2.1.17-基础知识之剖析theano的函数

    来自:http://deeplearning.net/software/theano/tutorial/profiling.html Profiling Theano function note:该方 ...

  2. Asp.net Mvc中利用ValidationAttribute实现xss过滤

    在网站开发中,需要注意的一个问题就是防范XSS攻击,Asp.net mvc中已经自动为我们提供了这个功能.用户提交数据时时,在生成Action参数的过程中asp.net会对用户提交的数据进行验证,一旦 ...

  3. unity3d 我的面试经历

    昨天在上海的一家公司面试成功了 这是我第一次面试,也是我的第一份工作 先上我的简历给大家参考下吧 个人简历 个人信息: 姓 名: 廖旭升         学 历: 无 民 族: 汉           ...

  4. Log4net使用(一)

    LogHelper.cs using NLog; using NLog.Targets; namespace MyProject.Tool.Log { public class LogHelper { ...

  5. [BZOJ2730][HNOI2012]矿场搭建(求割点)

    题目:http://www.lydsy.com:808/JudgeOnline/problem.php?id=2730 分析: 如果坍塌的点不是割点,那没什么影响,主要考虑坍塌的点是割点的情况. 显然 ...

  6. WinForm 问题集锦

    [1]重用项目窗体解决方案: 1. 把FmMain.cs 和 FmMain.Designer.cs 和 FmMain .resx 三个文件复制到程序目录下: 2. 在vs里面添加现有项, 选择FmMa ...

  7. coursera 公开课 文本挖掘和分析(text mining and analytics) week 1 笔记

    一.课程简介: text mining and analytics 是一门在coursera上的公开课,由美国伊利诺伊大学香槟分校(UIUC)计算机系教授 chengxiang zhai 讲授,公开课 ...

  8. C#,JavaScript两种语言 2048小游戏

    <html> <head> <style type="text/css"> .haha { border-width: 2; font-size ...

  9. PotPlayer 1.6.52965 美化版|视频播放器

    Potplayer播放器,基本上可以解析大部分的视频格式.作为单机版的视频播放器很不错的选择! Potplayer,只为播放而生! exp: 点击下载

  10. [转]Eclipse工具使用技巧总结

    首先推荐一篇非常好的How to use eclipse文章 ,讲的是eclipse使用的方方面面,非常实用,推荐给大家! 一.常用快捷键:Ctrl+F11 运行Ctrl+Shift+/ 在代码窗口中 ...