hdu 5908 暴力(map)

点击打开链接

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
using namespace std;
const int N=1e5+20;
int a[N],num[N],ans[N];
map<int,int>t1,t2;//值和出现次数 
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
	
		int n;
		cin>>n;
		int cur=0;
		for(int i=1;i<=n;i++)
		{
			scanf("%d",&a[i]);	
			if(n%i==0)
			{
				num[++cur]=i;//循环长度为n的因子 
			}
		}
		
		int cnt=0;
		//时间复杂度为 O(n*d(n)) 
		for(int k=1;k<=cur;k++)
		{
			bool flag=true;
			t1.clear();
			for(int j=1;j<=num[k];j++)
			{
				t1[a[j]]++;
			}
			int y=n/num[k];//循环次数
			for(int j=2;j<=y;j++) 
			{
				t2=t1;//
				int s=(j-1)*num[k]+1;//起点
				int t=s+num[k]-1;//终点
				for(;s<=t;s++)
				{
					t2[a[s]]--;
				}
				map<int,int>::iterator it;
				for(it=t2.begin();it!=t2.end();it++)
				{
					if(it->second)//次数相等时为0 
					{
						flag=false;
						break;
					}
				}
				if(!flag)
				break;
			} 
			if(flag)
			ans[++cnt]=num[k];
		}
		for(int i=1;i<=cnt;i++)
		{
			cout<<ans[i];
			
			if(i==cnt)
			cout<<endl;	
			else
			cout<<" ";
		}
	}	
	return 0;
} 


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值