B. Make Them Odd

There are nn positive integers a1,a2,…,ana1,a2,…,an. For the one move you can choose any even value cc and divide by two all elements that equal cc.

For example, if a=[6,8,12,6,3,12]a=[6,8,12,6,3,12] and you choose c=6c=6, and aa is transformed into a=[3,8,12,3,3,12]a=[3,8,12,3,3,12] after the move.

You need to find the minimal number of moves for transforming aa to an array of only odd integers (each element shouldn't be divisible by 22).

Input

The first line of the input contains one integer tt (1≤t≤1041≤t≤104) — the number of test cases in the input. Then tt test cases follow.

The first line of a test case contains nn (1≤n≤2⋅1051≤n≤2⋅105) — the number of integers in the sequence aa. The second line contains positive integers a1,a2,…,ana1,a2,…,an (1≤ai≤1091≤ai≤109).

The sum of nn for all test cases in the input doesn't exceed 2⋅1052⋅105.

Output

For tt test cases print the answers in the order of test cases in the input. The answer for the test case is the minimal number of moves needed to make all numbers in the test case odd (i.e. not divisible by 22).

Example

4
6
40 6 40 3 20 1
1
1024
4
2 4 8 16
3
3 1 7

output

4
10
4
0

  这是用c++的STL暴力过的,用set容器,他的特点就是各个元素是唯一的,相比于map,set还支持自定义排序,默认是int升序排列,字符是按字典序排列的

set的详细使用可以看:https://blog.csdn.net/byn12345/article/details/79523516

暴力不用多说直接看代码(带有注释):

//https://blog.csdn.net/sinat_37158899/article/details/79328104
#include<bits/stdc++.h>
using namespace std;
int a[200005];
bool cmp (int a,int b)
{
return a>b;
}
struct cmp2
{
bool operator () (const int a,const int b)
{
return a>b;//降序
}
};
set<int,cmp2> ss;//默认从小到大,将字符串按字母序进行排序。
int main(void)
{
int t,n;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%d",&a[i]);
}
sort(a+1,a+n+1,cmp); int top=0;int flag=0;
ss.clear(); for(int i=1;i<=n;i++){
if(a[i]!=a[i-1]&&a[i]%2==0)
ss.insert(a[i]),flag=1;
}
long long int ans=0;
set<int>::iterator it;
//printf("svdsvf\n");
while(flag)
{
flag=0;
//for(it=ss.begin();it!=ss.end();it++) printf("%d ",*it);
//printf("\n");
for(it=ss.begin();it!=ss.end();it++){
if(*it%2==0)
{
flag=1;
ans++;
int san=*it;
ss.erase(san);
san/=2;
//printf("没有失效:%d\n",*it);//set的it也会失效 ,vector的会
//注意不要使用过期的iterator
if(san%2==0)
ss.insert(san);
break;
}
}
}
printf("%lld\n",ans);
}
return 0;
}

  

codeforces B. Make Them Odd -C++stl之set的使用的更多相关文章

  1. Educational Codeforces Round 24 A 水 B stl C 暴力 D stl模拟 E 二分

    A. Diplomas and Certificates time limit per test 1 second memory limit per test 256 megabytes input ...

  2. codeforces 710C C. Magic Odd Square(构造)

    题目链接: C. Magic Odd Square Find an n × n matrix with different numbers from 1 to n2, so the sum in ea ...

  3. Codeforces Round #413 B T-shirt buying (STL set)

    链接:http://codeforces.com/contest/799/problem/B 题意: 给定n件衣服,对于第i(1<i<=n)件衣服,分别有价格pi,前颜色ai,后颜色bi三 ...

  4. CodeForces 990B Micro-World(思维、STL)

    http://codeforces.com/problemset/problem/990/B 题意: 有n个细菌,每个细菌的尺寸为ai,现在有以常数k,如果细菌i的尺寸ai大于细菌j的尺寸aj,并且a ...

  5. Codeforces 731 C.Socks-并查集+STL(vector+map)

      C. Socks   time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...

  6. Educational Codeforces Round 42D. Merge Equals(STL)

    D. Merge Equals time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...

  7. Codeforces Round #606(B-D)

    Dashboard - Codeforces Round #606 (Div. 2, based on Technocup 2020 Elimination Round 4) - Codeforces ...

  8. ACM International Collegiate Programming Contest, Tishreen Collegiate Programming Contest (2018) Syria, Lattakia, Tishreen University, April, 30, 2018

    ACM International Collegiate Programming Contest, Tishreen Collegiate Programming Contest (2018) Syr ...

  9. [Educational Codeforces Round 16]C. Magic Odd Square

    [Educational Codeforces Round 16]C. Magic Odd Square 试题描述 Find an n × n matrix with different number ...

随机推荐

  1. layui 动画 实现过程

    layui官方文档晦涩难懂,对小白特别不友好 为演示效果,js和css文件引用cdn 演示是ul套li标签进行演示,这不是固定的,你也可以div套div,div套span,外面和里面的标签类要一一对应 ...

  2. tkinter中Partial Function Example

    from functools import partial as pto from tkinter import Tk, Button, X from tkinter.messagebox impor ...

  3. Python知识点总结篇(一)

    Python基础 变量 变量类型: 1.数字型 整形:int: 浮点型:float: 布尔型:bool,True和False: 复数型:complex: 2.非数字型 字符串: 列表: 元祖: 字典: ...

  4. Go语言(环境的搭建)

    一步一步,从零搭建Go语言开发环境. 安装Go语言及搭建Go语言开发环境 下载 下载地址 Go官网下载地址:https://golang.org/dl/ Go官方镜像站(推荐):https://gol ...

  5. go 学习笔记 ----资源自动回收

    在释放局部资源时, 可以用defer管理 Go语言版本基于defer的Mutex用法 func safeRead(Mutex *mu) []byte { mu.Lock() defer mu.Unlo ...

  6. kubernetes-dashboard登录出现forbidden 403

    登录k8s dashboard https://xxxxx:6443/api/v1/namespaces/kube-system/services/https:kubernetes-dashboard ...

  7. c# 拼接字符串根据逗号切割 后转换成集合或数组

    版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明.本文链接:https://blog.csdn.net/qq_27559331/article/d ...

  8. JVM性能优化--JVM参数配置,使用JMeter简单测试配合说明参数调优

    一.JVM参数配置 1.常见参数配置 -XX:+PrintGC 每次触发GC的时候打印相关日志 -XX:+UseSerialGC 串行回收 -XX:+PrintGCDetails 更详细的GC日志 - ...

  9. Java中new和Class.forName的区别

    首先:New = Class.forName("pacage.A").newInstance(); new是关键字,直接创建对象.Class.forName()是一个方法,要求JV ...

  10. css3 media媒体查询器用法总结(附js兼容方法)

    css3 media媒体查询器用法总结 标签:class   代码   style   html   sp   src 随着响应式设计模型的诞生,Web网站又要发生翻天腹地的改革浪潮,可能有些人会觉得 ...