当前位置:网站首页>[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
}
边栏推荐
猜你喜欢
定时器的类型
tooltips使用教程(鼠标悬停时显示提示)
WPF project - basic usage of controls entry, you must know XAML
[Meetup Preview] OpenMLDB+OneFlow: Link feature engineering to model training to accelerate machine learning model development
The use of border controls
Kubernetes常用命令
mysql黑窗口~建库建表
Why don't you make a confession during the graduation season?
TRACE32 - C source code association
MySQL的相关问题
随机推荐
leetcode303 Weekly Match Replay
7. Summary of common interview questions
Doing things software development - the importance of law and understanding of reasonable conclusions
What is the difference between BI software in the domestic market?
JVM parameter analysis Xmx, Xms, Xmn, NewRatio, SurvivorRatio, PermSize, PrintGC "recommended collection"
【MySQL】Mysql范式及外键作用
MySQL database operations
ansible study notes 02
[MySQL] Mysql paradigm and the role of foreign keys
[Meetup Preview] OpenMLDB+OneFlow: Link feature engineering to model training to accelerate machine learning model development
多主复制的适用场景(1)-多IDC
多主复制下处理写冲突(4)-多主复制拓扑
Grafana安装后web打开报错
Ubantu project 4: xshell, XFTP connected the virtual machine and set xshell copy and paste the shortcut
org.apache.jasperException(could not initialize class org)
Precautions and solutions when SIGABRT error is reported
ML.NET related resources
Bilateral filtering acceleration "recommended collection"
工程水文学名词解释总结
苹果官网样式调整 结账时产品图片“巨大化”