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 ...
随机推荐
- Object-Widgets-Quick 构造树
Object Tree 当以某个QObject为父类创建一个QObject时, 它会被添加到该父类的children列表中. 析构时, QObjet 会首先检查自己的children, 依次析构, 然 ...
- 手工场景--controller--场景设计、场景监控、运行场景
场景设置: 1.设置界面 2.全局设置. A:初始化: B:启动用户: C:
- Mac + nginx + lua + luasocket + cjson
1. Lua // 官方网站 http://www.lua.org/ 下载源码包// 由于配合 nginx 使用, 所以使用 5.1.X 版本 $ .tar.gz $ cd lua- $ make m ...
- hdu 5997 rausen loves cakes(线段数合并+启发式修改)
题目链接:hdu 5997 rausen loves cakes 题意: 给你n个点,每个点有一个颜色,现在有两个操作,第一个操作,将颜色x改为颜色y,第二个操作,询问[x,y]区间有多少颜色段(颜色 ...
- java--调整JVM内存的大小
默认占用:64M的内存 修改内存的方式: 1.某一类,右键选择--Run Configurations 2.选择--Arguments 3.在VM argments中输入内容,如:-Xmx80m
- C# Where
判断一个字符串中是否包含字符串数组里的字符,恶意字符限制提交,一般人,包括最初的我,会这样写 public bool ValidateStr(string[] parms) { bool result ...
- android 实现与服务器的长链接 方式
http://blog.csdn.net/coffeeco/article/details/13276437 这边文章主要看服务端,使用tomcat7以上实现服务端的接收消息以及消息发送 http: ...
- Windows端口转发
1. PortTunnel 2. windows 自带的 netsh -----windows下也有一个小工具:portforward.exe,图形界面容易操作,个人平常使用可以,但是也没有办法实现与 ...
- Unity人工智能学习—确定性AI算法之追踪算法二
转自:http://blog.csdn.net/zhangxiao13627093203/article/details/47658673 上一篇讲到了追踪算法的比较简单的形式,看上去比较假,因为AI ...
- Proteus中MATRIX-8X8 LED灯的连接
上面8个引脚用于选择行,低电平有效.下面8个引脚用于选择列,高电平有效. 经测试,红色点阵LED与之相反,是上面的引脚用于选择列,且高电平有效:下面的引脚用于选择行,低电平有效. 在AT89C51单片 ...