CF980D Perfect Groups

题意:

将一个串划分为多个子集(不要求连续),要求同一子集内两任意元素的积为平方数

定义一个串的答案为所需的最少子集个数

一个长度为 n 的串有 n(n+1)2\frac{n(n+1)}{2}2n(n+1)​个非空子串,求答案为 1,2,3,⋯,n1,2,3,\cdots ,n1,2,3,⋯,n 的非空子串个数

题解:

这个不应该是紫题。。
先给结论:
如果a,b,c∈N+a,b,c∈N^+a,b,c∈N+,ab=n2ab=n^2ab=n2,bc=m2bc=m^2bc=m2,那么有ac=k2ac=k^2ac=k2。n,m,k∈N+n,m,k∈N^+n,m,k∈N+
你可以理解成有传递性
证明可以用唯一分解定理:

那么说明我们可以将这些平方数用并查集维护在一个集合里,然后n2n^2n2枚举所有子串暴力统计

代码:

#include<cmath>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define int long long
int n,x[5001],fa[5001],ans[5001],num[5001];
int find(int x)
{if(fa[x]==x)return x;return fa[x]=find(fa[x]);
}
void merge(int x,int y)
{fa[find(x)]=find(y);
}
signed main()
{scanf("%lld",&n);for(int i=1;i<=n;i++){scanf("%lld",&x[i]);fa[i]=i;}for(int i=1;i<=n;i++)for(int j=1;j<i;j++)if(x[i]*x[j]>0){int tmp=(int)sqrt(x[i]*x[j]);if(tmp*tmp==x[i]*x[j])merge(i,j);}for(int i=1;i<=n;i++){int tot=0;memset(num,0,sizeof(num));for(int j=i;j<=n;j++)if(x[j]==0)ans[max(1ll,tot)]++;else{if(!num[find(j)]){num[find(j)]=1;tot++;}ans[tot]++;}}for(int i=1;i<=n;i++)printf("%lld ",ans[i]);
}

CF980D Perfect Groups相关推荐

  1. cf round480D Perfect Groups

    题意:给一个序列,对于每一个连续的区间,区间内的数至少分成几个组,使得每个组内的数任意2个相乘是一个完全平方数(包括0). 输出每个组数的个数. $n \leq 5000 , |a_i| \leq 1 ...

  2. python的json格式输出_python中json格式数据输出实现方式

    python中json格式数据输出实现方式 主要使用json模块,直接导入import json即可. 小例子如下: #coding=UTF-8 import json info={} info[&q ...

  3. 卷积Groups Group Convolutions

    Symmetry Consider a square. Is it symmetric? How is it symmetric? How much symmetry does it have? Wh ...

  4. 367. Valid Perfect Square

    题目: Given a positive integer num, write a function which returns True if num is a perfect square els ...

  5. a prefect storm歌词_Storm s Perfect Storm歌词

    Storm s Perfect Storm歌词 添加日期:2003-05-05 时长:02分18秒 歌手:X Men Artist: Sara Evans Album: Sara Evans : Re ...

  6. limit_choices_to a value on a field in the same model - Google Groups

    limit_choices_to a value on a field in the same model - Google Groups: "" (Via.) 转载于:https ...

  7. Java was not the perfect solution for every pro...

    为什么80%的码农都做不了架构师?>>> When I started writing From Java to Ruby, I had a good idea that Java ...

  8. R语言使用dplyr聚合统计分组数据、ggplot2可视化分组线图、使用geom_line函数自定义设置线条类型、粗细、颜色(Change line types + colors by groups)

    R语言ggplot2可视化分组线图.使用geom_line函数自定义设置线条类型.宽度(粗细.).颜色(Change line types by groups.Change line types + ...

  9. Two Straws May Make a Perfect Diamond: Selecting Individually Weak Features for a Better Accuracy

    Two Straws May Make a Perfect Diamond: Selecting Individually Weak Features for a Better Accuracy 摘要 ...

最新文章

  1. GfK公司将IT设备移至Equinix公司在法兰克福的数据中心
  2. CIO黄嘉粤谈互联网金融与CIO发展
  3. python绘制灰度图片直方图-opencv+python 统计及绘制直方图
  4. Doxygen自动文档生成工具在Eclipse中的集成及使用举例
  5. 干货!策略路由和路由策略的区别和联系
  6. ?: (staticfiles.E002) The STATICFILES_DIRS setting should not contain the STATIC_ROOT setting.
  7. 深入浅出SQL(三)——表的规范化
  8. 软件项目管理课后题下载【共5个章(1、3、4、5、6)】
  9. makefile中的shell调用---注意事项
  10. FireMonkey 源码学习(4)
  11. matlab2c使用c++实现matlab函数系列教程-rank函数
  12. 行走在消逝中[LoLi有三好]
  13. NLP自然语言处理必修清单(修炼法则)
  14. 数据分析项目实战项目四:亚马逊Kindle书籍多渠道商业分析项目
  15. 计算机网络共享打不开,电脑系统网络和共享中心打不开怎么办
  16. 手机里面的照片被误删了怎么找回?
  17. GIthub上关于新冠肺炎数据整理的项目汇总
  18. 倍福PLC的Modbus-TCP Server入门教程
  19. 灵遁者引力理论,相对论的底层逻辑是什么?
  20. The Buffer Bomb

热门文章

  1. 柠檬汁制成的电池可以开动超100千克的车子吗?
  2. 舍不得删的12个优质公号
  3. android主动显示流程,Activity加载显示基本流程
  4. winserver2016 401您无权使用所提供的凭据查看此目录或页面_不用找了,30分钟帮你搞定使用 Spring Cloud 和 Docker 轻松构建微服务架构!...
  5. 如何证明服从卡方分布_谈谈抽样分布定理
  6. networkx 画有权图_利用NetworkX画网络图
  7. harmonyos con,鸿蒙HarmonyOS系统中的JS开发框架
  8. java不朽神迹,不朽的神迹 Eternal Legacy HD v1.0.8
  9. 计算机算法音乐专业,音乐信号分析算法的乐理简说(非音乐专业的乐理)
  10. 数据结构——最小生成树之克鲁斯卡尔算法(Kruskal)