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. Percona Xtrabackup 备份MySQL 实例(转)

    老规矩,开场白,刚开始用mysqldump,备份100G+的数据库,再加上服务器繁忙,备份速度像蜗牛似的,于是寻找更高效的备份方法.网上都说用xtrabackup比较适合备份大的数据库,而且备份效率也 ...

  2. css3 利用perspective实现翻页效果和正方体 以及翻转效果

    要点: 1 实现3D效果就需要使用perspective属性 1 页面旋转使用css3的rorate 2 使用backface-visibility 实现正面元素翻转之后背面不可见,显示出反面的元素 ...

  3. java基础知识(10)---包

    包:定义包用package关键字. 1:对类文件进行分类管理. 2:给类文件提供多层名称空间. 如果生成的包不在当前目录下,需要最好执行classpath,将包所在父目录定义到classpath变量中 ...

  4. 1、转载 bwa的使用方法

    http://bio-bwa.sourceforge.net/bwa.shtml http://www.plob.org/?p=25 bwa的使用需要两中输入文件: Reference genome ...

  5. 序列化 (C#)

    序列化是指将对象转换成字节流,从而存储对象或将对象传输到内存.数据库或文件的过程. 它的主要用途是保存对象的状态,以便能够在需要时重新创建对象. 反向过程称为"反序列化". 序列化 ...

  6. sqlserver2012——SqlCommand创建对象的三种方法

    1.使用不带参构造函数 SqlCommand cmd = new SqlCommand(); cmd.Connection = SqlConnnection对象: cmd.CommandText=Sq ...

  7. 网络应用(3):CDN与P2P的概念

    我前面说了流量的概念,流量是使用网络时经常要考虑的一个因素--如何才能更快的使用流量,如何才能节省流量使用的成本,对于这样的问题,你可能要了解一下什么是cdn,什么是p2p. (1)cdn是什么 cd ...

  8. python接口自动化(三十五)-封装与调用--流程类接口关联(详解)

    简介 流程相关的接口,主要用 session 关联,如果写成函数(如上篇),s 参数每个函数都要带,每个函数多个参数,这时候封装成类会更方便.在这里我们还是以博客园为例,带着小伙伴们实践一下. 接口封 ...

  9. Codeforces Round #517 (Div. 2, based on Technocup 2019 Elimination Round 2)D(思维,DP,字符串)

    #include<bits/stdc++.h>using namespace std;char c[2007][2007];char ans[4007];int s[2007][2007] ...

  10. oracle批量插入带主键自增

    https://blog.csdn.net/qq_37630354/article/details/82792288