hdu_5908_Abelian Period(暴力)
题意:
给你n个数字,让你找出所有的k,使得把这n个数字分为k分,并且每份的数字种类和个数必须相同
题解:
枚举k,首先k必须是n的约数,然后就能算出每个数字应该出现多少次,O(n)检验即可。
#include<bits/stdc++.h>
#define F(i,a,b) for(int i=a;i<=b;++i)
using namespace std; const int N=1e5+;
int t,n,a[N];
map<int,int>A,B;
map<int,int>::iterator it;
int ans[N],ed; int main(){
scanf("%d",&t);
while(t--)
{
scanf("%d",&n),ed=;
F(i,,n)scanf("%d",a+i);
int be=;
while(be<=n)
{
while(be<n&&n%be!=)be++;
if(n%be==)
{
A.clear();
F(i,,be)A[a[i]]++;
int en=n/be,fg=;
F(i,,en)
{
B=A;
int s=(i-)*be+,t=s+be-;
F(j,s,t)B[a[j]]--;
for(it=B.begin();it!=B.end();it++)
{
if(it->second!=){fg=;break;}
}
if(fg)break;
}
if(fg==)ans[++ed]=be;
}
be++;
}
F(i,,ed)printf("%d%c",ans[i],i==ed?'\n':' ');
}
return ;
}
hdu_5908_Abelian Period(暴力)的更多相关文章
- 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. ...
- HDU5908 Abelian Period 暴力
题目大意:将一个数组分成长度为k的几个连续区间,如果每个区间内各个元素出现的次数相同,则称k为一个阿贝尔周期,从小到大打印所有阿贝尔周期,数据间加空格. 题目思路:map+暴力 #include< ...
- 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 ...
- centos 7 DenyHosts 安装 防暴力破解ssh登陆
为了减少软件扫描ssh登陆 还是用这个比较好点 默认端口号22 也要改 登陆密码也不要使用 弱口令 123456 这样的 Description DenyHosts is a python prog ...
- 欧拉工程第64题:Odd period square roots
题目链接 找循环位数是奇数的数有多少个 这个自己很难写出来,完全不能暴力 维基百科链接 维基百科上面说的很好,上面的算法实现就好了. 就是上面的 Java程序: package project61; ...
- hdu 1010 Tempter of the Bone(dfs暴力)
Problem Description The doggie found a bone in an ancient maze, which fascinated him a lot. However, ...
- Codeforces Round #404 (Div. 2)(A.水,暴力,B,排序,贪心)
A. Anton and Polyhedrons time limit per test:2 seconds memory limit per test:256 megabytes input:sta ...
- Codeforces 827E Rusty String - 快速傅里叶变换 - 暴力
Grigory loves strings. Recently he found a metal strip on a loft. The strip had length n and consist ...
随机推荐
- MFC中CListCtrl说明
转载:http://blog.csdn.NET/lhy2199/article/details/5177032 listctrl默认view 风格为report CListCtrl类封装"列 ...
- LED :制作一个追逐序列(霹雳游侠)
; ,,}; ; void setup() { ; led<NbrLeds; led++){ pinMode(ledPins[led], OUTPUT); } } void loop() { ; ...
- subsequence/subsets/subarray/substring problems
128. Longest Consecutive Sequence hashmap, int up = nums[i], int down, int max 注:访问过的要erase 152. Max ...
- sql第三天
->完整的select语句及执行顺序(必须记住) 5...select 5.2->distinct 7...top n [percent] 5.1->列名 聚合函数(1.2-> ...
- Ajax中参数带有html格式的 传入后台保存【二】
KindEditor.ready(function (K) { //编辑器插件 window.editor1 = K.create('#ctjs', { uploadJson: '/Hotelgl/U ...
- [河南省ACM省赛-第三届] 聪明的kk (nyoj 171)
题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=171 动态规划: d(i,j) = max{d(i-1, j), d(i, j-1)}+m ...
- Struts2的通配符配置方式
Struts2的Action类很有意思,你可以使用3种方式来实现具体的Action类: 让你的Action类继承自ActionSupport类(项目中最常用这种方式,因为ActionSupport类中 ...
- 学习任务在继续...css...
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- WPF 命令的简单总结
WPF的命令Command主要解决的问题,就是代码复用.一个很重要的应用意义,在于它将很多地方需要的调用的相同操作,以统一的方式管理,却又提供了不同的访问结果. 举个例子来说,我可能通过“点击butt ...
- C++从函数返回指针
C++ 允许您从函数返回指针.为了做到这点,必须声明一个返回指针的函数,如下所示: int * myFunction() { . . . } 另外,C++ 不支持在函数外返回局部变量的地址,除非定义局 ...