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 解题思路: 题意为询问一段区间里的数能组成多少段连续的数.先考虑从左往右一个数一个数添加,考虑当 ...
随机推荐
- WPF 绑定枚举值
前台Xaml <ComboBox x:Name=" HorizontalAlignment="Left" Margin="5 0 0 0" Se ...
- 【python游戏编程之旅】第七篇---pygame中的冲突检测技术
本系列博客介绍以python+pygame库进行小游戏的开发.有写的不对之处还望各位海涵. 上一个博客我们一起学习了pygame中的Sprite模块和如何加载动画:http://www.cnblogs ...
- 构建Spark的Eclipse开发环境
前言 无论Windows 或Linux 操作系统,构建Spark 开发环境的思路一致,基于Eclipse 或Idea,通过Java.Scala 或Python 语言进行开发.安装之前需要提前准备好JD ...
- Position、Float
http://www.cnblogs.com/coffeedeveloper/p/3145790.html
- Android开发之补间动画、XML方式定义补间动画
四种补间动画: 1.透明: 2.缩放: 3.位移: 4.旋转: //点击按钮 实现iv 透明的效果 动画 public void click1(View v) { //1.0意味着着完全不透明 0.0 ...
- html 文本超过显示省略号
display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2;//显示行数 word-break: break-a ...
- Spring 向页面传值以及接受页面传过来的参数的方式
来源于:http://www.cnblogs.com/liuhongfeng/p/4802013.html 一.从页面接收参数 Spring MVC接收请求提交的参数值的几种方法: 使用HttpSer ...
- 【CodeVS 3289】【NOIP 2013】花匠
http://codevs.cn/problem/3289/ dp转移,树状数组维护前缀max和后缀max进行优化,$O(nlogn)$. #include<cstdio> #includ ...
- 【CodeVS 2083】Cryptcowgraphy 解密牛语
http://codevs.cn/problem/2083/ 奶牛搜索题.我加了如下剪枝: 1.用字符串hash判重.注意判重时也要对字符串长度判重,否则会出现两个字符串长度不同但hash值相同的情况 ...
- 评价指标ROC,PR
之前实习的时候一直见公司里面的人说什么AUC, 实际AUC就是ROC曲线的面积 PR是precise和recall曲线,和ROC的区别是,当测试集中的正负样本分布变化的时候,ROC曲线能够保持不变,而 ...