http://acm.hdu.edu.cn/showproblem.php?pid=5908

要求把数组分成k组使得每组中的元素出现次数相同

就是分成k个集合,那么直接用multiset判定就可以

有重载相等运算符的

我被坑了的就是,

对于2个元素一个集合的可以,那么,4,6,8这样分集合也是可以的。

这个很容易理解

但是,你也要能平均分才行啊

就是10的2可以,但是4是一定不可以得。不能平均分

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL; #include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
const int maxn = + ;
int a[maxn];
multiset<int>aa;
multiset<int>bb;
set<int>ans;
void work() {
aa.clear();
// bb.clear();
ans.clear();
int n;
scanf("%d", &n);
bool flag = true;
for (int i = ; i <= n; ++i) {
scanf("%d", &a[i]);
if (i >= && a[i] != a[i - ]) flag = false;
}
ans.insert(n);
if (flag) {
for (int i = ; i <= n / ; ++i) {
if (n % i == ) {
ans.insert(i);
}
}
} else {
int begin = , end = -;
for (int i = ; i <= n / ; ++i) {
if (n % i != ) continue;
if (ans.find(i) != ans.end()) continue;
// aa.clear();
end = i;
// cout << begin << " " << end << " " << i << endl;
for (int j = begin; j <= end; ++j) {
aa.insert(a[j]);
}
begin = end + ;
flag = true;
for (int j = * i; j <= n; j += i) {
bb.clear();
for (int k = j; k >= j - i + ; --k) {
bb.insert(a[k]);
}
if (aa != bb) {
flag = false;
break;
}
}
if (!flag) continue;
for (int j = i ; j <= n / ; j += i) {
if (n % j == ) //10的2不代表10的4
ans.insert(j);
}
}
}
// show();
set<int> :: iterator it = ans.begin();
printf("%d", *it);
it++;
for (; it != ans.end(); ++it) {
printf(" %d", *it);
}
printf("\n");
return;
} int main() {
#ifdef local
freopen("data.txt","r",stdin);
#endif
int t;
scanf("%d", &t);
while(t--) work();
return ;
}
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL; #include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
const int maxn = + ;
int a[maxn];
bool isok[maxn];
int n;
int cnt[maxn];
int cmp[maxn];
bool check(int val) {
for (int i = ; i <= val; ++i) {
cnt[a[i]] = ;
}
for (int i = ; i <= val; ++i) {
cnt[a[i]]++;
}
for (int i = * val; i <= n; i += val) {
for (int j = i; j >= i - val + ; --j) {
cmp[a[j]] = ;
}
for (int j = i; j >= i - val + ; --j) {
cmp[a[j]]++;
}
for (int j = ; j <= val; ++j) {
if (cnt[a[j]] != cmp[a[j]]) return false;
}
}
return true;
}
void work() {
scanf("%d", &n);
bool flag = true;
memset(isok, , sizeof isok);
isok[n] = ;
for (int i = ; i <= n; ++i) {
scanf("%d", &a[i]);
if (i >= && a[i] != a[i - ]) flag = false;
}
if (flag) {
for (int i = ; i <= n / ; ++i) {
if (n % i == ) {
isok[i] = ;
}
}
} else {
for (int i = ; i <= n / ; ++i) {
if (n % i != || isok[i]) continue;
if (check(i)) {
for (int j = i; j <= n / ; ++j) {
if (n % j == ) isok[i] = ;
}
}
}
}
flag = ;
for (int i = ; i <= n; ++i) {
if (isok[i]) {
if (!flag) {
printf("%d", i);
flag = ;
} else {
printf(" %d", i);
}
}
}
printf("\n");
return;
} int main() {
#ifdef local
freopen("data.txt","r",stdin);
#endif
int t;
scanf("%d", &t);
while(t--) work();
return ;
}

HDU 5908 Abelian Period 可以直接用multiset的更多相关文章

  1. HDU 5908 Abelian Period (BestCoder Round #88 模拟+暴力)

    HDU 5908 Abelian Period (BestCoder Round #88 模拟+暴力) 题目链接http://acm.hdu.edu.cn/showproblem.php?pid=59 ...

  2. HDU 5908 Abelian Period 暴力

    Abelian Period 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5908 Description Let S be a number st ...

  3. 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. ...

  4. 每日学习笔记:js中可以直接用id名调用的问题?

    在JavaScript中,标准的id选择器调用语法是: document.getElementById('myid').style.width = pc + "%"; 但是,今天发 ...

  5. 只用@property定义一个属性speed,子类不能直接用_speed,需要在interface的成员变量列表里写上_speed

    //写法一: @interface Person : NSObject { } @property (nonatomic, strong) NSString *name; @end @implemen ...

  6. 直接用<img> 的src属性显示base64转码后的字符串成图片

    直接用<img> 的src属性显示base64转码后的字符串成图片 <img src="base64转码后的字符串" ></img> 下面的图片 ...

  7. 在nginx中配置如何防止直接用ip访问服务器web server及server_name特性讲解

    看了很多nginx的配置,好像都忽略了ip直接访问web的问题,不利于SEO优化,所以我们希望可以避免直接用IP访问网站,而是域名访问,具体怎么做呢,看下面. 官方文档中提供的方法: If you d ...

  8. 直接用Qt写soap

    直接用Qt写soap 最近的项目里用到了webservice, 同事用的是`gSoap`来搞的. 用这个本身没什么问题, 但这货生成的代码实非人类可读, 到处都是`__`和`_`, 看得我眼晕.... ...

  9. 为什么是List list = new ArrayList() 而不直接用ArrayList

    为什么是List list = new ArrayList(),而不直接用ArrayList? 编程是要面向对象编程,针对抽象(接口),而非具体.List 是接口,ArrayList是实现. 实现Li ...

随机推荐

  1. Excel对重复数据分组,求出不同的数据(office 2013)

    第一步: 第二步: 第三步:

  2. JVM插庄之一:JVM字节码增强技术介绍及入门示例

    字节码增强技术:AOP技术其实就是字节码增强技术,JVM提供的动态代理追根究底也是字节码增强技术. 目的:在Java字节码生成之后,对其进行修改,增强其功能,这种方式相当于对应用程序的二进制文件进行修 ...

  3. stm32之内部功能

    本文将提到以下内容: 位带操作 中断 printf重定向 随机数发生器RNG AD/DA DMA 高性能计算能力 加密 ART加速 一.位带操作 在学习51单片机的时候就使用过位操作,通过关键字sbi ...

  4. java中的接口和抽象类的区别

    1.接口从用户的角度(使用实现的代码)看问题. 2.接口由编译器强制的一个模块间协作的合约. 3.无成员变量. 4.成员函数只能声明不能实现,(jdk1.8中的default 方法可以有方法体). 接 ...

  5. mysql--二进制日志(bin-log)

    一.设置二进制日志 进制日志记录了所有的DDL和DML,但不包括各种查询.通过二进制日志,可以实现什么效果呢?二进制日志文件可以[实现灾难数据恢复],另外可以应用到[mysql复制数据同步].二进制日 ...

  6. [51nod1247]可能的路径(思维题)

    题意:给定(a,b),(x,y)  ,(a,b)可以通向(a-b,b) (a+b,b) (a,a+b) (a,a-b) 求能否到达(x,y) 解题关键:类似于更相减损,变换过程中gcd是一样的. #i ...

  7. DOM 中 Property 和 Attribute 的区别(转)

    property 和 attribute非常容易混淆,两个单词的中文翻译也都非常相近(property:属性,attribute:特性),但实际上,二者是不同的东西,属于不同的范畴. property ...

  8. R语言 arules包 apriori()函数中文帮助文档(中英文对照)

    apriori(arules) apriori()所属R语言包:arules                                         Mining Associations w ...

  9. 8. CTF综合靶机渗透(一)

    靶机说明 虚拟机难度中等,使用ubuntu(32位),其他软件包有: PHP apache MySQL 目标 Boot to root:从Web应用程序进入虚拟机,并获得root权限. 运行环境 靶机 ...

  10. 使用VS Code配合Remote Development插件连接远程服务器(Mac/Linux+Windows) | Using VS Code with Remote Development Connect to Remote Server (Mac/Linux+Windows)

    最新版VS Code(2019年6月)出了一系列新的插件,包括Remote Development,Remote SSH等,使得用户可以使用VS Code远程连接服务器写代码,方便了协同工作.具体配置 ...