HDU 5908 Abelian Period (BestCoder Round #88 模拟+暴力)
HDU 5908 Abelian Period (BestCoder Round #88 模拟+暴力)
题目链接http://acm.hdu.edu.cn/showproblem.php?pid=5908
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
题意:
给你n个数字,首先你可以以没k个为一段,要求n分成的各个段中数字的数量和个数都相同。
题解:
首先枚举每个可以被n整除的段,然后再判断是否可以即可,枚举sqrt(n)或者n/2暴力都可以。
判断的方法:首先我们先统计每个元素的个数,对于k个元素一组,因为是均分的,所以每组出现多少个就确定了。现在我们从开始往后面扫,首先没k个一组,多少组就确定了,那么我们现在看,在每一段该元素都有每个数字的出现上限。如果超过了那么必然是错误的k划分,同时我们记录下到达该数字上限的数的个数,和之前的统计如果不同返回false。最终返回true,这样就求出。
代码:
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100000+100;
int s[maxn+10];
int rec[maxn+10];
bool fuck[maxn+10];
int db[maxn+10];
int ans[maxn+10];
int n;
int tol = 0;
inline bool sol(int k)
{
int tt = n / k;
memset(db,0,sizeof db);
for (int i = 0; i < tt; i++){
int temp = 0;
for (int j = 1; j <= k; j++){
db[s[i*k+j]]++;
if (db[s[i*k+j]]*tt > rec[s[i*k+j]]*(i+1))
return false;
else if (db[s[i*k+j]]*tt == rec[s[i*k+j]]*(i+1))
temp++;
}
if (temp != tol)
return false;
}
return true;
}
int main()
{
int t;
scanf("%d",&t);
while (t--){
tol = 0;
int ta = 0;
memset(rec,0,sizeof rec) ;
scanf("%d",&n);
for (int i = 1; i <= n; i++){
scanf("%d",&s[i]);
rec[s[i]]++;
}
for (int i = 1; i <= maxn; i++)
if (rec[i] != 0)
tol++;
for (int i = 1; i*2 <= n; i++){
if (n%i == 0){
if (sol(i))
printf("%d ",i);
}
}
printf("%d\n",n);
}
return 0;
}
HDU 5908 Abelian Period (BestCoder Round #88 模拟+暴力)的更多相关文章
- 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(暴力+想法题)
传送门 Description Let S be a number string, and occ(S,x) means the times that number x occurs in S. i. ...
- HDU 5908 Abelian Period 可以直接用multiset
http://acm.hdu.edu.cn/showproblem.php?pid=5908 要求把数组分成k组使得每组中的元素出现次数相同 就是分成k个集合,那么直接用multiset判定就可以 有 ...
- BestCoder Round #88
传送门:BestCoder Round #88 分析: A题统计字符串中连续字串全为q的个数,预处理以下或加个cnt就好了: 代码: #include <cstdio> #include ...
- hdu 4956 Poor Hanamichi BestCoder Round #5(数学题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4956 Poor Hanamichi Time Limit: 2000/1000 MS (Java/Ot ...
- HDU - 5996 树上博弈 BestCoder Round #90
就是阶梯NIM博弈,那么看层数是不是奇数的异或就行了: #include<iostream> #include<cstdio> #include<algorithm> ...
- HDU 5904 - LCIS (BestCoder Round #87)
HDU 5904 - LCIS [ DP ] BestCoder Round #87 题意: 给定两个序列,求它们的最长公共递增子序列的长度, 并且这个子序列的值是连续的 分析: 状态转移方程式 ...
- [BestCoder Round #3] hdu 4907 Task schedule (模拟简单题)
Task schedule Problem Description 有一台机器,而且给你这台机器的工作表.工作表上有n个任务,机器在ti时间运行第i个任务,1秒就可以完毕1个任务. 有m个询问,每一个 ...
- hdu 5667 BestCoder Round #80 矩阵快速幂
Sequence Accepts: 59 Submissions: 650 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536 ...
随机推荐
- 使用Excel背单词-高效-简单
背单词是一个很纠结的事,想必那些走在留学路上的很多人都被英语这一关卡住了,这里,笔者就聊聊,不讲背单词的方法,只提供使用vb开发的产品和使用方法,有问题欢迎讨论. 简介:使用excel背单词,有一些人 ...
- Run SPLAHS2 under SE mode on gem5在gem5的SE模式下,运行SPLASH2程序
1. 安装相关的gem5,可以参考以前的博客. 2. 下载splash2编译好的软件 首先从gem5的官网下载已经编译成alpha指令集的splash2.下载地址:http://www.gem5. ...
- Quagga添加自己的命令
参考了王斌的文档:http://down.51cto.com/data/621454 TIP:笔者使用的版本是0.99.20 需求:在接口模式下添加一条"ip ospf enable&quo ...
- [C++]neuroscan的延时预估
一直用自己写的程序在线处理脑电信号,知道其中有一个时间延时,但具体延时是多少没有是个准确的估计,今天抽时间做了一下,发现大概延时在100ms左右. 以后尝试使用并口操作.应该可以完全避免这个问题. 实 ...
- DNS解析详细过程
英文:domain name system. 中文:域名系统. 解析过程: 第一次请求站点(例:http://www.baidu.com),先在当前浏览器路径下寻找有没有缓存对应的解析结果,如果有的话 ...
- RHEL账号总结一:账号的分类
账号是一种用来记录单个用户或者多个用户的数据.RHEL中每一个合法的用户都必须拥有账号,才能使用RHEL. 在RHEL上的账号可以分为两类: 用户账号:用来存储单一用户的数据,你也可以使用一个用户账号 ...
- 间隔Ns请求某函数并且有timeout
实现方案: 1. 递归调用 2.timer:apply_interval() 3.gen_server来写 时间timeout怎么实现: 1.开始时间存入ets表中 2.put,get方法放入进程字典 ...
- BZOJ1013 [JSOI2008]球形空间产生器sphere(高斯消元)
1013: [JSOI2008]球形空间产生器sphere Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 4846 Solved: 2525[Subm ...
- VC 2008 Express下安装OpenCV2.3.1
VC 2008 Express下安装OpenCV2.3.1 注意: 下列文档以VC2008 Express为例,VC2010下的配置应与本文档类似. VC 6.0不被OpenCV 2.3.1支持. ...
- 【.NET】字符串处理类库
类名:DealString,方法清单列好在头上. /// 1.截取字符串,最后加3个小数点 /// 2.获得指定Url的参数的string类型值 /// 3.判断数据类型 /// 4.过滤JS标记 / ...
题目链接http://acm.hdu.edu.cn/showproblem.php?pid=5908
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
题意:
给你n个数字,首先你可以以没k个为一段,要求n分成的各个段中数字的数量和个数都相同。
题解:
首先枚举每个可以被n整除的段,然后再判断是否可以即可,枚举sqrt(n)或者n/2暴力都可以。
判断的方法:首先我们先统计每个元素的个数,对于k个元素一组,因为是均分的,所以每组出现多少个就确定了。现在我们从开始往后面扫,首先没k个一组,多少组就确定了,那么我们现在看,在每一段该元素都有每个数字的出现上限。如果超过了那么必然是错误的k划分,同时我们记录下到达该数字上限的数的个数,和之前的统计如果不同返回false。最终返回true,这样就求出。
代码:
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100000+100;
int s[maxn+10];
int rec[maxn+10];
bool fuck[maxn+10];
int db[maxn+10];
int ans[maxn+10];
int n;
int tol = 0;
inline bool sol(int k)
{
int tt = n / k;
memset(db,0,sizeof db);
for (int i = 0; i < tt; i++){
int temp = 0;
for (int j = 1; j <= k; j++){
db[s[i*k+j]]++;
if (db[s[i*k+j]]*tt > rec[s[i*k+j]]*(i+1))
return false;
else if (db[s[i*k+j]]*tt == rec[s[i*k+j]]*(i+1))
temp++;
}
if (temp != tol)
return false;
}
return true;
}
int main()
{
int t;
scanf("%d",&t);
while (t--){
tol = 0;
int ta = 0;
memset(rec,0,sizeof rec) ;
scanf("%d",&n);
for (int i = 1; i <= n; i++){
scanf("%d",&s[i]);
rec[s[i]]++;
}
for (int i = 1; i <= maxn; i++)
if (rec[i] != 0)
tol++;
for (int i = 1; i*2 <= n; i++){
if (n%i == 0){
if (sol(i))
printf("%d ",i);
}
}
printf("%d\n",n);
}
return 0;
}
Abelian Period 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5908 Description Let S be a number st ...
传送门 Description Let S be a number string, and occ(S,x) means the times that number x occurs in S. i. ...
http://acm.hdu.edu.cn/showproblem.php?pid=5908 要求把数组分成k组使得每组中的元素出现次数相同 就是分成k个集合,那么直接用multiset判定就可以 有 ...
传送门:BestCoder Round #88 分析: A题统计字符串中连续字串全为q的个数,预处理以下或加个cnt就好了: 代码: #include <cstdio> #include ...
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4956 Poor Hanamichi Time Limit: 2000/1000 MS (Java/Ot ...
就是阶梯NIM博弈,那么看层数是不是奇数的异或就行了: #include<iostream> #include<cstdio> #include<algorithm> ...
HDU 5904 - LCIS [ DP ] BestCoder Round #87 题意: 给定两个序列,求它们的最长公共递增子序列的长度, 并且这个子序列的值是连续的 分析: 状态转移方程式 ...
Task schedule Problem Description 有一台机器,而且给你这台机器的工作表.工作表上有n个任务,机器在ti时间运行第i个任务,1秒就可以完毕1个任务. 有m个询问,每一个 ...
Sequence Accepts: 59 Submissions: 650 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536 ...
背单词是一个很纠结的事,想必那些走在留学路上的很多人都被英语这一关卡住了,这里,笔者就聊聊,不讲背单词的方法,只提供使用vb开发的产品和使用方法,有问题欢迎讨论. 简介:使用excel背单词,有一些人 ...
1. 安装相关的gem5,可以参考以前的博客. 2. 下载splash2编译好的软件 首先从gem5的官网下载已经编译成alpha指令集的splash2.下载地址:http://www.gem5. ...
参考了王斌的文档:http://down.51cto.com/data/621454 TIP:笔者使用的版本是0.99.20 需求:在接口模式下添加一条"ip ospf enable&quo ...
一直用自己写的程序在线处理脑电信号,知道其中有一个时间延时,但具体延时是多少没有是个准确的估计,今天抽时间做了一下,发现大概延时在100ms左右. 以后尝试使用并口操作.应该可以完全避免这个问题. 实 ...
英文:domain name system. 中文:域名系统. 解析过程: 第一次请求站点(例:http://www.baidu.com),先在当前浏览器路径下寻找有没有缓存对应的解析结果,如果有的话 ...
账号是一种用来记录单个用户或者多个用户的数据.RHEL中每一个合法的用户都必须拥有账号,才能使用RHEL. 在RHEL上的账号可以分为两类: 用户账号:用来存储单一用户的数据,你也可以使用一个用户账号 ...
实现方案: 1. 递归调用 2.timer:apply_interval() 3.gen_server来写 时间timeout怎么实现: 1.开始时间存入ets表中 2.put,get方法放入进程字典 ...
1013: [JSOI2008]球形空间产生器sphere Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 4846 Solved: 2525[Subm ...
VC 2008 Express下安装OpenCV2.3.1 注意: 下列文档以VC2008 Express为例,VC2010下的配置应与本文档类似. VC 6.0不被OpenCV 2.3.1支持. ...
类名:DealString,方法清单列好在头上. /// 1.截取字符串,最后加3个小数点 /// 2.获得指定Url的参数的string类型值 /// 3.判断数据类型 /// 4.过滤JS标记 / ...