HDU 5908 Abelian Period(暴力+想法题)
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(暴力+想法题)的更多相关文章
- HDU 5908 Abelian Period 暴力
Abelian Period 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5908 Description Let S be a number st ...
- HDU 5908 Abelian Period (BestCoder Round #88 模拟+暴力)
HDU 5908 Abelian Period (BestCoder Round #88 模拟+暴力) 题目链接http://acm.hdu.edu.cn/showproblem.php?pid=59 ...
- HDU 5908 Abelian Period 可以直接用multiset
http://acm.hdu.edu.cn/showproblem.php?pid=5908 要求把数组分成k组使得每组中的元素出现次数相同 就是分成k个集合,那么直接用multiset判定就可以 有 ...
- HDU - 5806 NanoApe Loves Sequence Ⅱ 想法题
http://acm.hdu.edu.cn/showproblem.php?pid=5806 题意:给你一个n元素序列,求第k大的数大于等于m的子序列的个数. 题解:题目要求很奇怪,很多头绪但写不出, ...
- HDU 4972 Bisharp and Charizard 想法题
Bisharp and Charizard Time Limit: 1 Sec Memory Limit: 256 MB Description Dragon is watching NBA. He ...
- HDU - 5969 最大的位或 想法题
http://acm.hdu.edu.cn/showproblem.php?pid=5969 (合肥)区域赛签到题...orz 题意:给你l,r,求x|y的max,x,y满足l<=x<=y ...
- HDU 5632 Rikka with Array [想法题]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5632 ------------------------------------------------ ...
- HDU5908 Abelian Period 暴力
题目大意:将一个数组分成长度为k的几个连续区间,如果每个区间内各个元素出现的次数相同,则称k为一个阿贝尔周期,从小到大打印所有阿贝尔周期,数据间加空格. 题目思路:map+暴力 #include< ...
- HDU 4638 树状数组 想法题
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4638 解题思路: 题意为询问一段区间里的数能组成多少段连续的数.先考虑从左往右一个数一个数添加,考虑当 ...
随机推荐
- redis性能测试tcp socket and unix domain
UNIX Domain Socket IPC socket API原本是为网络通讯设计的,但后来在socket的框架上发展出一种IPC机制,就是UNIX Domain Socket.虽然网络socke ...
- Linux进程间通信之管道
1,进程间通信 (IPC ) Inter-Process Communication 比较好理解概念的就是进程间通信就是在不同进程之间传播或交换信息. 2,linux下IPC机制的分类:管道.信号.共 ...
- 20160803 - C:\WINDOWS\system32\config\systemprofile\Desktop 不可用的解决
问题:某些软件在从注册表读取用户桌面地址时,欠考虑的%USERPROFILE%的情况,例如迅雷打开文件时,会提示: [Window Title]位置不可用 [Content]C:\WINDOWS\sy ...
- 从 datetime2 数据类型到 datetime 数据类型的转换产生一个超出范围的值
具体的错误原因是:C#中的DateTime类型比SqlServer中的datetime范围大.SqlServer的datetime有效范围是1753年1月1日到9999年12月31日,如果超出这个范围 ...
- go linux 学习记录
1 yum install mercurial 安装mercurial包 2 yum install git 安装git包 3 yum install gcc 安装gcc 4 然后就可以下载gola ...
- C语言变参数函数
#include<iostream> #include<stdarg.h> using namespace std; int sum(int cnt, ...){ va_lis ...
- 我的第一个DMZ方案实践
方案提出的初衷:外网需要定时和不定时推送数据到内网服务器(只要求数据到达内网,没有要求直接连接到内网) 为什么不是直连到内网:每个人第一想到的是不安全,是的,没错不安全.内网的应用和外网的应用最明显的 ...
- python基础-内置函数详解
一.内置函数(python3.x) 内置参数详解官方文档: https://docs.python.org/3/library/functions.html?highlight=built#ascii ...
- Tomcat6查看数据库的数据源信息
打开tomcat6\conf 下的 context.xml
- window配置nginx+php+mysql
博客来源: http://www.cnblogs.com/wuzhenbo/p/3493518.html 启用nginx D:\nginx>nginx.exe 重启 D:\nginx> ...