HDU 5908 Abelian Period 可以直接用multiset
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的更多相关文章
- HDU 5908 Abelian Period (BestCoder Round #88 模拟+暴力)
HDU 5908 Abelian Period (BestCoder Round #88 模拟+暴力) 题目链接http://acm.hdu.edu.cn/showproblem.php?pid=59 ...
- HDU 5908 Abelian Period 暴力
Abelian Period 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5908 Description Let S be a number st ...
- 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. ...
- 每日学习笔记:js中可以直接用id名调用的问题?
在JavaScript中,标准的id选择器调用语法是: document.getElementById('myid').style.width = pc + "%"; 但是,今天发 ...
- 只用@property定义一个属性speed,子类不能直接用_speed,需要在interface的成员变量列表里写上_speed
//写法一: @interface Person : NSObject { } @property (nonatomic, strong) NSString *name; @end @implemen ...
- 直接用<img> 的src属性显示base64转码后的字符串成图片
直接用<img> 的src属性显示base64转码后的字符串成图片 <img src="base64转码后的字符串" ></img> 下面的图片 ...
- 在nginx中配置如何防止直接用ip访问服务器web server及server_name特性讲解
看了很多nginx的配置,好像都忽略了ip直接访问web的问题,不利于SEO优化,所以我们希望可以避免直接用IP访问网站,而是域名访问,具体怎么做呢,看下面. 官方文档中提供的方法: If you d ...
- 直接用Qt写soap
直接用Qt写soap 最近的项目里用到了webservice, 同事用的是`gSoap`来搞的. 用这个本身没什么问题, 但这货生成的代码实非人类可读, 到处都是`__`和`_`, 看得我眼晕.... ...
- 为什么是List list = new ArrayList() 而不直接用ArrayList
为什么是List list = new ArrayList(),而不直接用ArrayList? 编程是要面向对象编程,针对抽象(接口),而非具体.List 是接口,ArrayList是实现. 实现Li ...
随机推荐
- bzoj 3144 切糕 —— 最小割
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3144 每个点拆成 R 个,连成一条链,边上是权值,割掉代表选这一层: 然后每个点的第 t 层 ...
- css关于内外边距的详细解释
贴图吧,图一眼明了. 无效果时候有 只有一个<div>啦啦啦</div> 只有padding时候有: padding详细设计时: 解释:padding是对内的,如padding ...
- project online get approvals task data 获取审批待办任务接口
调用接口地址:重要 http://xxxx/sites/pwa/_vti_bin/PSI/ProjectServer.svc Header 三个必要参数: 其中SOAPAction写死就行,如果是on ...
- BO 与 VO 的属性拷贝 copyProperties(bo,vo)
NewClass extends OldClass : newClass继承自oldClass,属性大多数相同,但是也有新的扩展. beanUtils.copyProperties(oldClas ...
- <table>的使用以及确定取消按钮的设置
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- SpringCloud01 服务提供者和消费者
说明:服务消费者直接利用RestTemplate调用服务提供者,这种使用方式只是适用于微服务数量比较少的项目,如果微服务的数量比较多建议使用SpringCloud提供的Eureaka组件. 注意:实现 ...
- windows、Linux 测试服务器、电脑的某些个端口是否打开
测试远程端口是否开放包括两种方法: 一. 命令行的形式 二.代码 先参考我的博客 windows.Linux 开放端口 一.命令行的形式 两个命令:telnet.nc(netcat) 两种网络层协议: ...
- windows10 Ubuntu子系统下卸载Mysql重装
首先删除mysql: sudo apt-get remove mysql-* 然后清理残留的数据 dpkg -l |grep ^rc|awk '{print $2}' |sudo xargs dpkg ...
- ARC097D Equals
传送门 题目 We have a permutation of the integers from 1 through N, p1, p2, .., pN. We also have M pairs ...
- Git 客户端在 WebIDE 中的实现
Coding WebIDE 是 Coding.net 自主研发的在线集成开发环境 (IDE).你可以通过 WebIDE 创建项目的工作空间, 进行在线开发, 调试等操作,有功能健全的 Terminal ...