题目链接: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(暴力)的更多相关文章

  1. 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. ...

  2. HDU5908 Abelian Period 暴力

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

  3. HDU 5908 Abelian Period 暴力

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

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

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

  5. centos 7 DenyHosts 安装 防暴力破解ssh登陆

    为了减少软件扫描ssh登陆 还是用这个比较好点  默认端口号22 也要改 登陆密码也不要使用 弱口令 123456 这样的 Description DenyHosts is a python prog ...

  6. 欧拉工程第64题:Odd period square roots

    题目链接 找循环位数是奇数的数有多少个 这个自己很难写出来,完全不能暴力 维基百科链接 维基百科上面说的很好,上面的算法实现就好了. 就是上面的 Java程序: package project61; ...

  7. hdu 1010 Tempter of the Bone(dfs暴力)

    Problem Description The doggie found a bone in an ancient maze, which fascinated him a lot. However, ...

  8. 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 ...

  9. Codeforces 827E Rusty String - 快速傅里叶变换 - 暴力

    Grigory loves strings. Recently he found a metal strip on a loft. The strip had length n and consist ...

随机推荐

  1. iOS -OC调用js页面

    我们这边和h5商量好传递一个结构体参数过去,然后由于解析的问题,导致我这里传递的参数,到h5那边不执行那边的方法 -(void)loginCallBack { NSDictionary *dic; u ...

  2. C#重写url

    string url = Request.Url.LocalPath; Context.RewritePath(url + "?id=1111&name=gdwy"); 或 ...

  3. redis(1)

    一.Redis介绍 Redis 是一款开源的,基于 BSD 许可的,高级键值 (key-value) 缓存 (cache) 和存储 (store) 系统.由于 Redis 的键包括 string,ha ...

  4. [SQL基础教程] 1-5 表的删除和更新

    [SQL基础教程] 1-5 表的删除和更新 表的删除 语法 DROP TABLE <表名>; 法则 1-12 删除的表无法恢复 表定义的更新 语法 ALTER TABLE<表名> ...

  5. chd校内选拔赛题目+题解

    题目链接   A. Currency System in Geraldion 有1时,所有大于等于1的数都可由1组成.没有1时,最小不幸的数就是1. #include<iostream> ...

  6. HDU 1013 Digital Roots(字符串)

    Digital Roots Problem Description The digital root of a positive integer is found by summing the dig ...

  7. 多线程随笔二(Task)

    Task类是.net 4.0新加进来的特性,对原有的Thread,ThreadPool做了进一步的封装,使得.net平台上的多线程编程变得更加方便.废话不多说,进入正题. 一. Task启动 Task ...

  8. readline与readlines不能同时使用

    fd = open("C:\Users\william\Desktop\dup_file - Copy (2).txt")for i in xrange(0,len(fd.read ...

  9. Codeforces Round #346 (Div. 2) A Round-House

    A. Round House 题目链接http://codeforces.com/contest/659/problem/A Description Vasya lives in a round bu ...

  10. iOS 导航栏 不透明

    UINavigationBar.appearance().translucent = false UINavigationBar.appearance().barStyle = UIBarStyle. ...