当前位置:网站首页>[7.28] Code Source - [Fence Painting] [Appropriate Pairs (Data Enhanced Version)]
[7.28] Code Source - [Fence Painting] [Appropriate Pairs (Data Enhanced Version)]
2022-07-31 15:49:00 【ZhgDgE】
#735. Fence Painting
题意:有编号从 1 1 1 开始的 n ( 1 ≤ n ≤ 1 0 5 ) n(1\leq n\leq 10^5) n(1≤n≤105) 块木板, 第 i i i The color of the boards is a i a_i ai,you want to put the i i i The color of the boards is dyed b i b_i bi .
有 m m m Each painter will come to work in turn,第 j j j A painter will dye a certain board a color c j c_j cj ,You can specify which piece they dye,But can not be stained.
Determine if all boards can be dyed the target color,如果能,输出方案
思路:The time-reversed processing of the dictionary.对于 b b b 序列,我们按照 b i b_i bi 进行分组.对于 c i c_i ci ,如果在 b i b_i bi There are corresponding colors in ,We definitely prioritize dyeing where things need to be changed,Then there are the places that don't need to be changed.If there is no corresponding color,Just find a place that has been dyed(In positive chronological order it will be overwritten by later colors),If you can't find it, it's definitely a no-brainer.
AC代码:http://oj.daimayuan.top/submission/306521
#733. 合适数对(数据加强版)
题意:给定一个长度为 n ( 1 ≤ n ≤ 1 0 6 ) n(1\leq n\leq 10^6) n(1≤n≤106) 的正整数数列 a ( 1 ≤ a i ≤ 1 0 7 ) a(1\leq a_i\leq 10^7) a(1≤ai≤107) 和一个正整数 k ( 1 ≤ k ≤ 100 ) k(1\leq k\leq 100) k(1≤k≤100). 请你判断共有多少个数对 ( l , r ) (l,r) (l,r) 满足:
1 ≤ l < r ≤ n 1≤l<r≤n 1≤l<r≤n,存在一个整数 x x x 使得 a l × a r = x k a_l×a_r=x^k al×ar=xk 成立
题解:(质因数分解)代码源每日一题 Div1 合适数对(数据加强版)
思路:首先,The product is a positive integer k k k 次方,From the point of view of prime factors,The degree of multiplying each prime factor must be k k k 的倍数.Then we make the degree pairs of the prime factors of each number k k k 取余,If the sum of the degrees of each prime factor of two numbers is 0 0 0 或 k k k ,Then it must be a satisfying pair of numbers.
Then the way to deal with it is:Treat each number as a prime factor modulo k k k 的乘积,Then store it in a bucket.由 a r a_r ar 求 a l a_l al 也很简单.This question is very strict,Both the modulo and the modulo are turned on int ,The speed ratio of this mode LL 稍快一些.
Learned here a new sieve prime number method,比 之前的 更优:
- The smallest prime factor that preprocesses all numbers,Then just use the prime factor to sieve,时间复杂度 O ( n ∼ log n ) O(n\sim \log n) O(n∼logn)
while(num > 1){
int cnt = 0, m = minp[num];
while(num % m == 0) cnt ++ , num /= m;
// m ^ cnt
}
边栏推荐
- Emmet syntax
- tooltips使用教程(鼠标悬停时显示提示)
- 删除 状态良好(恢复分区)的磁盘
- MySQL基础篇【单行函数】
- 苹果官网样式调整 结账时产品图片“巨大化”
- 腾讯云部署----DevOps
- Applicable scenario of multi-master replication (2) - client and collaborative editing that require offline operation
- C语言”三子棋“升级版(模式选择+AI下棋)
- 6-22 Vulnerability exploit - postgresql database password cracking
- 2.索引及调优篇【mysql高级】
猜你喜欢
随机推荐
定时器的类型
ansible study notes 02
T - sne + data visualization parts of the network parameters
The principle of hough transform detection of straight lines (opencv hough straight line detection)
Precautions and solutions when SIGABRT error is reported
基于Redis(SETNX)实现分布式锁,案例:解决高并发下的订单超卖,秒杀
MySQL多表联合查询
R language test whether the sample conforms to normality (test whether the sample comes from a normally distributed population): shapiro.test function tests whether the sample conforms to the normal d
SQL、HQL、JPQL 到底有什么区别
Vb how to connect mysql_vb how to connect to the database collection "advice"
Matlab matrix basic operations (definition, operation)
.NET 20th Anniversary Interview - Zhang Shanyou: How .NET technology empowers and changes the world
Handling write conflicts under multi-master replication (4) - multi-master replication topology
Matlab矩阵基本操作(定义,运算)
6-22漏洞利用-postgresql数据库密码破解
TRACE32 - C source code association
MySQL数据库操作
Deployment应用生命周期与Pod健康检查
工程流体力学复习
Unity 之 图集属性详解和代码示例 -- 拓展一键自动打包图集工具








