当前位置:网站首页>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;
}
边栏推荐
- "Wei Lai Cup" 2022 Niuke summer multi school training camp 2 personal problem sets
- I just test it
- Digital transformation behind the reshaping growth of catering chain stores
- 推荐系统-协同过滤在Spark中的实现
- 网络之二三层转发
- 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
- proto转换Dart | 项目使用Protobuf | flutter 使用grpc
- 【深入浅出玩转FPGA学习11----Testbench书写技巧1】
- npm ERR! code ETIMEDOUTnpm ERR! syscall connectnpm ERR! errno ETIMEDOUTnpm ERR! network request t
- Recommend a super good UI automation tool: uiautomator2!
猜你喜欢

How to use the pagoda panel to deploy the full stack project of node to the server

Record a failure caused by a custom redis distributed lock

Cross Site Request Forgery (CSRF): impact, examples, and Prevention

What is a test case? How to design?
![Niuke - bm39 serialized binary tree [hard]](/img/c4/f14fe8488bbf28689fa3f02cdf4dae.png)
Niuke - bm39 serialized binary tree [hard]

Protect syslog servers and devices

SVN版本控制分支、合并功能使用

Understand Linglong platform unified access service from simple to deep Monet

元素和小于等于阈值的正方形的最大边长(来源:力扣(LeetCode))

Three modes of CPU
随机推荐
ABC find 4-cycle (pigeon nest theorem)
Stack Title: basic calculator
Practice sharing of monorepo based on yarn1.x
FFT用于估计插值后的图像重采样因子
Leetcode/ numbers that appear only once
Niuke - bm39 serialized binary tree [hard]
In spark SQL, date is used to display the day of the week according to the year, month and day_ format(date,‘u‘)
推荐⼀款超好⽤的UI⾃动化⼯具: UiAutomator2!
How to do Taobao live broadcast and how to do the anchor to drain and sell products
SOC first project hello_ world
《穷爸爸与富爸爸》读后小结
Easyrecovery15 data recovery software with high recovery rate and high download volume
Is it safe to open an account for stock speculation through the online account manager?
Basic version of Google browser debugging tool (I)
Big view +500 cases, software teams should improve R & D efficiency in this way
NFT access tool premint was hacked and lost more than 370000 US dollars
“蔚来杯“2022牛客暑期多校训练营2 D.[Link with Game Glitch] 二分答案+SPFA判环
“蔚来杯“2022牛客暑期多校训练营2 K.[Link with Bracket Sequence I] 括号序列 DP
How to use the pagoda panel to deploy the full stack project of node to the server
01. MySQL transaction isolation level and concurrent database access