当前位置:网站首页>[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
}
边栏推荐
- The R language ggstatsplot package ggbarstats function visualizes bar charts, and adds hypothesis test results (including sample number, statistics, effect size and its confidence interval, significan
- 6-22漏洞利用-postgresql数据库密码破解
- Deployment application life cycle and Pod health check
- ML.NET related resources
- Linux查看redis版本(查看mongodb版本)
- leetcode303 Weekly Match Replay
- 工程流体力学复习
- The use of button controls
- T - sne + data visualization parts of the network parameters
- MySQL多表联合查询
猜你喜欢
随机推荐
【MySQL】Mysql范式及外键作用
更新数据表update
.NET 20th Anniversary Interview - Zhang Shanyou: How .NET technology empowers and changes the world
多主复制的适用场景(2)-需离线操作的客户端和协作编辑
基于ABP实现DDD
Premiere Pro 2022 for (pr 2022)v22.5.0
字符指针赋值[通俗易懂]
Synchronized and volatile interview brief summary
C程序是如何跑起来的01 —— 普通可执行文件的构成
What is the difference between BI software in the domestic market?
软件实现AT命令操作过程
MySQL多表联合查询
浏览器自带的拾色器
The 2nd China PWA Developer Day
MySQL数据库操作
BGP综合实验(建立对等体、路由反射器、联邦、路由宣告及聚合)
Handling write conflicts under multi-master replication (4) - multi-master replication topology
数据库的范式(第一范式,第二范式,第三范式,BCNF范式)「建议收藏」
Insert into data table to insert data
The new BMW 3 Series is on the market, with safety and comfort