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. import module, from module import funtion区别

    import module与from module import funtion区别: import module导入模块后你需要使用module.function()来调用一个函数 from mod ...

  2. Image Sub-pixel interpolation by Verilog

    bilinear interpolation -------------------------------------------------------- input a0  a1 b0  b1 ...

  3. MongoDB优化之三:如何排查MongoDB CPU利用率高的问题

    遇到这个问题,99.9999% 的可能性是「用户使用上不合理导致」,本文主要介绍从应用的角度如何排查 MongoDB CPU 利用率高的问题. Step1: 分析数据库正在执行的请求 用户可以通过 M ...

  4. JavaScript-Tool:template

    ylbtech-JavaScript-Tool: 1.返回顶部   2.返回顶部   3.返回顶部   4.返回顶部   5.返回顶部     6.返回顶部   作者:ylbtech出处:http:/ ...

  5. linux->windows主动推送文件同步目录数据 linux-windows数据目录同步

    1 .windows下安装openssh for windows工具,下载地址 https://www.mls-software.com/opensshd.html 2.修改openssh安装目录下e ...

  6. 将Linux 标准输出,错误输出重定向到文件

    1.想要把make输出的全部信息,输出到某个文件中,最常见的办法就是: make xxx > build_output.txt 此时默认情况是没有改变2=stderr的输出方式,还是屏幕,所以, ...

  7. ASP.NET MVC中的ActionFilter介绍学习

    一直都知道MVC中的ActionFilter,只是没有在实际项目中使用过. 顾名思义,ActionFilter就是指在Action上的Filter, 那么,在Action上的Filter到底有哪些呢. ...

  8. 解决Navicat 无法连接mysql8.0

    必须执行下面两个步骤,缺一不可. 一.        mysql8.0加密方式与mysql5几加密方式不同,需要先更改加密方式. 更改加密方式 ALTERUSER 'root'@'localhost' ...

  9. 多个VSTO解决方案间传输变量

    参照微软官方文档,为需要公开参数的解决方案添加公开接口.不过稍显遗憾的是,不能传输List泛型 https://docs.microsoft.com/zh-cn/visualstudio/vsto/c ...

  10. Linux命令使用

    命令行创建设置用户密码 $ sudo useradd -m -r username $ cat "username:password" | sudo chpasswd -m 查询u ...