当前位置:网站首页>F. Equal multisets (greedy)
F. Equal multisets (greedy)
2022-07-26 01:48:00 【to cling】
Codeforces Round #805 (Div. 3)
Problem
Let's say that both lengths are n Array of a and b. Every time you can be right b One of the two operations is performed by any number in :(1) Multiply by two (2) Take down and divide by two .
The operation sequence is not limited , The number of times is unlimited , ask : After some operation ,b Can you communicate with a identical .
Solution
- First of all, you can put a Divide the number in by two , Until it becomes odd .
reason : If b Arrays can become a Array , that , It can also become a changed array . If it cannot be changed into a changed array , It means there is no solution . - here a There are odd numbers in the array , Then the operation is invalid . Only operation two is left .
- because b The number in can only be reduced now , therefore , It should be from b The maximum number in starts to operate continuously .
If it turns into 0 Can't with a One of the numbers is the same , So there's no solution .
Code
const int N = 2e5 + 5, M = 1e6 + 7;
int a[N], b[N];
map<int, int> mp;
int main()
{
IOS;
int T; cin >> T;
while (T--)
{
mp.clear();
int n; cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= n; i++) cin >> b[i];
for (int i = 1; i <= n; i++)
{
while (a[i] % 2 == 0) a[i] /= 2;
mp[a[i]]++;
}
sort(b + 1, b + n + 1, greater<int>());
int f = 1;
for (int i = 1; i <= n; i++)
{
while (b[i] && mp[b[i]] == 0)
b[i] /= 2;
if (b[i] == 0) f = 0;
else mp[b[i]]--;
}
if (f) cout << "YES\n";
else cout << "NO\n";
}
return 0;
}
边栏推荐
- “蔚来杯“2022牛客暑期多校训练营2 个人题解集合
- Is it safe to buy funds on e fund? Professional answers
- FFT is used to estimate the image resampling factor after interpolation
- 销量连连夺冠,五菱的成功秘诀只有低价吗?
- Nodejs builds cloud native microservice applications based on dapr, a quick start guide from 0 to 1
- 【深入浅出玩转FPGA学习11----Testbench书写技巧1】
- “蔚来杯“2022牛客暑期多校训练营2 D.[Link with Game Glitch] 二分答案+SPFA判环
- [Unity] 二维洞穴地图随机生成
- SVN版本控制分支、合并功能使用
- The detailed knowledge summary of MySQL can be collected
猜你喜欢

Codisvsrediscluster: which cluster scheme should I choose?

Two stage submission and three stage submission

IDEA如何快速删除最近打开的项目

推荐系统-协同过滤在Spark中的实现

Format JS code and debug JS code

Go operation excel library excel use

IP address of the network

How idea can quickly delete recently opened projects
![4QAM, 16QAM modulation and demodulation simulation circuit, observe and analyze QAM constellation and bit error rate curve [matlab code]](/img/95/5b9a2347d20cc5da0d2920b7f583ce.png)
4QAM, 16QAM modulation and demodulation simulation circuit, observe and analyze QAM constellation and bit error rate curve [matlab code]

Leetcode 537. complex multiplication (netizens' thoughts, ashamed)
随机推荐
“蔚来杯“2022牛客暑期多校训练营2 I.[let fat tension] 矩阵乘法 J.[Link with Arithmetic Progression]线性回归
【深入浅出玩转FPGA学习11----Testbench书写技巧2】
言语理解-片段阅读的结构剖析练习
Silicon Valley classroom - official account cloud on demand Silicon Valley classroom microservice project practical notes
3059. 雕塑(jzoj)
Format JS code and debug JS code
网络之IP地址
SQL injection tutorial: learn through examples
Is it safe to buy funds in stock accounts? Professional answers
My Mysql to MySQL data table synchronization, only the code written in the first order will take effect, and the rest will not take effect. This may be
【深入浅出玩转FPGA学习11----Testbench书写技巧1】
Shell exercises
[Verilog digital system design (Xia Yuwen) 4 ----- basic concepts of Verilog syntax 2]
When everything can be metauniverse, the development of metauniverse seems to have entered a new stage of development
AutoCAD -- Method of calculating area
"Wei Lai Cup" 2022 Niuke summer multi school training camp 2 personal problem sets
Stack Title: basic calculator
3、 Pinda general permission system__ pd-tools-swagger2
Big view +500 cases, software teams should improve R & D efficiency in this way
Typora expiration solution, what if typora can't open