HDU5908 Abelian Period(模拟暴力)
来源:互联网 发布:张辛苑的淘宝店 编辑:程序博客网 时间:2024/05/21 09:34
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=5908
Abelian Period
Accepts: 288
Submissions: 984
Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 262144/131072 K (Java/Others)
问题描述
设S是一个数字串,定义函数occ(S,x)表示S中数字x的出现次数。例如:S=(1,2,2,1,3),occ(S,1)=2,occ(S,2)=2,occ(S,3)=1。如果对于任意的i,都有occ(u,i)=occ(w,i),那么我们认为数字串u和w匹配。例如:(1,2,2,1,3)≈(1,3,2,1,2)。对于一个数字串S和一个正整数k,如果S可以分成若干个长度为k的连续子串,且这些子串两两匹配,那么我们称k是串S的一个完全阿贝尔周期。给定一个数字串S,请找出它所有的完全阿贝尔周期。
输入描述
输入的第一行包含一个正整数T(1≤T≤10),表示测试数据的组数。对于每组数据,第一行包含一个正整数n(n≤100000),表示数字串的长度。第二行包含n个正整数S1,S2,S3,...,Sn(1≤Si≤n),表示这个数字串。
输出描述
对于每组数据,输出一行若干个整数,从小到大输出所有合法的k。
输入样例
265 4 4 4 5 486 5 6 5 6 5 5 6
输出样例
3 62 4 8
解题思路:用有点技巧的暴力吧,有点像欧拉筛法筛素数的感觉,详情看代码吧。
/* ***********************************************┆ ┏┓ ┏┓ ┆┆┏┛┻━━━┛┻┓ ┆┆┃ ┃ ┆┆┃ ━ ┃ ┆┆┃ ┳┛ ┗┳ ┃ ┆┆┃ ┃ ┆┆┃ ┻ ┃ ┆┆┗━┓ 马 ┏━┛ ┆┆ ┃ 勒 ┃ ┆ ┆ ┃ 戈 ┗━━━┓ ┆┆ ┃ 壁 ┣┓┆┆ ┃ 的草泥马 ┏┛┆┆ ┗┓┓┏━┳┓┏┛ ┆┆ ┃┫┫ ┃┫┫ ┆┆ ┗┻┛ ┗┻┛ ┆************************************************ */#include <stdio.h>#include <string.h>#include <iostream>#include <algorithm>#include <vector>#include <queue>#include <stack>#include <set>#include <map>#include <string>#include <math.h>#include <stdlib.h>#include <bitset>using namespace std;#define rep(i,a,b) for (int i=(a),_ed=(b);i<=_ed;i++)#define per(i,a,b) for (int i=(b),_ed=(a);i>=_ed;i--)#define pb push_back#define mp make_pairconst int inf_int = 2e9;const long long inf_ll = 2e18;#define inf_add 0x3f3f3f3f#define mod 1000000007#define LL long long#define ULL unsigned long long#define MS0(X) memset((X), 0, sizeof((X)))#define SelfType intSelfType Gcd(SelfType p,SelfType q){return q==0?p:Gcd(q,p%q);}SelfType Pow(SelfType p,SelfType q){SelfType ans=1;while(q){if(q&1)ans=ans*p;p=p*p;q>>=1;}return ans;}#define Sd(X) int (X); scanf("%d", &X)#define Sdd(X, Y) int X, Y; scanf("%d%d", &X, &Y)#define Sddd(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)#define reunique(v) v.resize(std::unique(v.begin(), v.end()) - v.begin())#define all(a) a.begin(), a.end()#define mem(x,v) memset(x,v,sizeof(x))typedef pair<int, int> pii;typedef pair<long long, long long> pll;typedef vector<int> vi;typedef vector<long long> vll;inline int read(){int ra,fh;char rx;rx=getchar(),ra=0,fh=1;while((rx<'0'||rx>'9')&&rx!='-')rx=getchar();if(rx=='-')fh=-1,rx=getchar();while(rx>='0'&&rx<='9')ra*=10,ra+=rx-48,rx=getchar();return ra*fh;}//#pragma comment(linker, "/STACK:102400000,102400000")const int N = 1e5 + 5;int a[N],t[N],p[N],q[N],ok[N];int cnt;int n;int check(int x){ cnt++; for(int i=1;i<=x;i++) { t[a[i]] = cnt; p[a[i]] = 0; } for(int i=1;i<=x;i++) p[a[i]]++; for(int i=1;i<n/x;i++) { int L = i * x + 1; int R = L + x - 1; for(int j=1;j<=x;j++) q[a[j]] = 0; for(int j=L;j<=R;j++) { if(t[a[j]] != cnt) return 0; if(++q[a[j]] > p[a[j]]) return 0; } } return 1;}int main(){//freopen("in.txt","r",stdin);//freopen("out.txt","w",stdout);ios::sync_with_stdio(0);cin.tie(0);int t;t = read();while(t--) { n = read(); for(int i=1;i<=n;i++) a[i] = read(); MS0(ok); for(int i=1;i<=n;i++) { if(n%i==0 && !ok[i]) { if(check(i)) { for(int j=i;j<=n;j+=i) { if(n%j==0) ok[j] = 1; } } } } int flag = 0; for(int i=1;i<=n;i++) { if(ok[i]) { if(flag)printf(" "); flag = 1; printf("%d",i); } } printf("\n"); }return 0;}
0 0
- HDU5908 Abelian Period(模拟暴力)
- HDU5908-Abelian Period
- hdu5908 Abelian Period (water)
- HDU5908 Abelian Period
- hdu5908 Abelian Period 暴力 小小小小的优化
- HDU 5908 Abelian Period(暴力)
- HDU-5908-Abelian Period(暴力)
- HDU 5908 Abelian Period (暴力+map)
- hdu 5908 Abelian Period 模拟
- hdu 5908 Abelian Period【思维+暴力枚举】
- hdu 5908 Abelian Period(暴力 + map优化)
- HDU -- 5908 Abelian Period 【思维 + map + 暴力】
- HDU 5908 Abelian Period 模拟乱搞
- Abelian Period
- Abelian Period
- 【HDU 5908 || #bestcoder88 1002】【map的应用 暴力】Abelian Period
- HDU5908【模拟】
- HDU:5908 Abelian Period(水题+技巧)
- 1000的阶乘-HDU 1042-大数阶乘(万进制思想)
- 单显卡台式机(Ubuntu15.04+Win7)安装Cuda7.5+cuDnn v4 心路历程
- 积性函数前缀和求和的方法
- 第一次机房收费之充值
- Go语言基础:变量赋值顺序
- HDU5908 Abelian Period(模拟暴力)
- 剑指offer:二叉树的镜像(java)
- 从功能模块角度看ARM Cortex-M各处理器区别
- window环境中0.python1.Numpy 2. Scipy 3. Matplotlib 4. Scikit-Learn的安装
- ucos-II(四)
- Linux线程3种同步方法
- Exchange Online 邮件迁移最佳实践(二)
- codeforces Destroying Array 线段树维护区间
- 图像偏色检测算法,速度快,效果好,共享给大家。