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 ...
随机推荐
- d指针在Qt上的应用及实现
Qt为了使其动态库最大程度上实现二进制兼容,引入了d指针的概念.那么为什么d指针能实现二进制兼容呢?为了回答这个问题,首先弄清楚什么是二进制兼容?所谓二进制兼容动态库,指的是一个在老版本库下运行的程序 ...
- Android自定义组合控件内子控件无法显示问题
今天自定义了一个组合控件,与到了个奇葩问题: 我自定义了一个RelativeLayout,这个layout内有多个子控件.但奇怪的是这些子控件一直显示不出来.调试了一下午,竟然是因为在获取(infla ...
- Bitmap的读写
Bitmap的读写和几个小儿科的滤镜效果~ 闲来玩玩图像处理,拿破仑说过:“不想自己实现滤镜的美工不是好程序员~~#@!*^...#&!@......” 因为在学校做过很多美工的工作,而且从 ...
- 机器学习的Spark与Scala开发简介
一.机器学习常用开发软件:Spark.Scala 1. Spark简介: MLlib包含的库文件有: 分类 降维 回归 聚类 推荐系统 自然语言处理 在线学习 统计学习方法:偏向理论性,数理统计的方 ...
- 自定义JSP中的Taglib标签之四自定义标签中的Function函数
转自http://www.cnblogs.com/edwardlauxh/archive/2010/05/19/1918589.html 之前例子已经写好了,由于时间关系一直没有发布,这次带来的是关于 ...
- Java Volatile transient 关键字
随笔-204 评论-134 文章-0 trackbacks-0 Volatile修饰的成员变量在每次被线程访问时,都强迫从主内存中重读该成员变量的值.而且,当成员变量发生变化时,强迫线程将变 ...
- (细节控)swift3.0与融云IMKIT开发问题(一部分) override func onSelectedTableRow Method does not override any method from its superclass
原官网文档方案如下,在swift3.0的情况下出现 override func onSelectedTableRow Method does not override any method from ...
- HDU--1006
题目介绍 Problem Description The three hands of the clock are rotating every second and meeting each oth ...
- IE条件注释,嗅探低版本IE用户,并引导升级
一.科普IE条件注释 IE条件注释功能是条件注释是IE特有的一种功能,能对IE系列产品进行单独的XHTML代码处理,注意,主要是针对XHTML,而非CSS.条件注释功能非常强大,可以进行true和fa ...
- html css jquery 回到顶部按钮
今天做了个回到顶部的功能,在这里记录一下,有需要可以拿去试试! CSS部分,很简单就一个class /*回到顶部*/ .back-top { position: fixed; right: 15px; ...
题目链接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 ...
Qt为了使其动态库最大程度上实现二进制兼容,引入了d指针的概念.那么为什么d指针能实现二进制兼容呢?为了回答这个问题,首先弄清楚什么是二进制兼容?所谓二进制兼容动态库,指的是一个在老版本库下运行的程序 ...
今天自定义了一个组合控件,与到了个奇葩问题: 我自定义了一个RelativeLayout,这个layout内有多个子控件.但奇怪的是这些子控件一直显示不出来.调试了一下午,竟然是因为在获取(infla ...
Bitmap的读写和几个小儿科的滤镜效果~ 闲来玩玩图像处理,拿破仑说过:“不想自己实现滤镜的美工不是好程序员~~#@!*^...#&!@......” 因为在学校做过很多美工的工作,而且从 ...
一.机器学习常用开发软件:Spark.Scala 1. Spark简介: MLlib包含的库文件有: 分类 降维 回归 聚类 推荐系统 自然语言处理 在线学习 统计学习方法:偏向理论性,数理统计的方 ...
转自http://www.cnblogs.com/edwardlauxh/archive/2010/05/19/1918589.html 之前例子已经写好了,由于时间关系一直没有发布,这次带来的是关于 ...
随笔-204 评论-134 文章-0 trackbacks-0 Volatile修饰的成员变量在每次被线程访问时,都强迫从主内存中重读该成员变量的值.而且,当成员变量发生变化时,强迫线程将变 ...
原官网文档方案如下,在swift3.0的情况下出现 override func onSelectedTableRow Method does not override any method from ...
题目介绍 Problem Description The three hands of the clock are rotating every second and meeting each oth ...
一.科普IE条件注释 IE条件注释功能是条件注释是IE特有的一种功能,能对IE系列产品进行单独的XHTML代码处理,注意,主要是针对XHTML,而非CSS.条件注释功能非常强大,可以进行true和fa ...
今天做了个回到顶部的功能,在这里记录一下,有需要可以拿去试试! CSS部分,很简单就一个class /*回到顶部*/ .back-top { position: fixed; right: 15px; ...