当前位置:网站首页>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;
}
边栏推荐
- pdf. JS introduction
- The best way to practice Animation: cover transition
- Cross Site Request Forgery (CSRF): impact, examples, and Prevention
- Handler message mechanism - FWK layer
- leetcode/只出现一次的数字
- Oracle is nested at multiple levels, and the alias problem of the table cannot be found
- The sales volume has won the championship repeatedly. Is the secret of Wuling's success only low price?
- Go operation excel library excel use
- IDEA如何快速删除最近打开的项目
- 3059. 雕塑(jzoj)
猜你喜欢

Integer data type in C language (do you really understand it)

Speech comprehension - structural analysis exercise of fragment reading

保护系统日志服务器和设备

Handler message mechanism - FWK layer

Codisvsrediscluster: which cluster scheme should I choose?
SQL injection tutorial: learn through examples

【Verilog数字系统设计(夏宇闻)4-----Verilog语法的基本概念2】

CPU的三种模式

Google gson usage details

Fiddler5+ lightning simulator 4.0 settings for app packet capturing
随机推荐
Quickly create a topic folder
How idea can quickly delete recently opened projects
AutoCAD -- Method of calculating area
销量连连夺冠,五菱的成功秘诀只有低价吗?
The detailed knowledge summary of MySQL can be collected
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
【独立站建设】shopify卖家:学会这几点,网上商店销量翻倍!
leetcode/只出现一次的数字
"Weilai Cup" 2022 Niuke summer multi school training camp 2 g.[link with monotonic subsequence] block structure
Practice sharing of monorepo based on yarn1.x
Speech comprehension center comprehension summary
NFT access tool premint was hacked and lost more than 370000 US dollars
Is it safe to buy funds on e fund? Professional answers
Maximum side length of elements and squares less than or equal to the threshold (source: leetcode)
Stack Title: basic calculator
“蔚来杯“2022牛客暑期多校训练营2 K.[Link with Bracket Sequence I] 括号序列 DP
Cross Site Request Forgery (CSRF): impact, examples, and Prevention
Leetcode/ numbers that appear only once
Pt onnx ncnn conversion problem record (followed by yolov5 training)
01. MySQL transaction isolation level and concurrent database access