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. 微信小程序获取微信绑定的手机号

    怎么获取微信绑定手机号呢?我们授权登录的时候,我们只能获取微信登录人员的头像,昵称,性别之类的,而手机号需要二次授权才可以,那么获取手机号都需要哪些条件呢?来看官方文档 获取手机号 获取微信用户绑定的 ...

  2. Scala 系列(七)—— 常用集合类型之 Map & Tuple

    一.映射(Map) 1.1 构造Map // 初始化一个空 map val scores01 = new HashMap[String, Int] // 从指定的值初始化 Map(方式一) val s ...

  3. C# vb .net实现装饰边框效果滤镜

    在.net中,如何简单快捷地实现Photoshop滤镜组中的装饰边框效果呢?答案是调用SharpImage!专业图像特效滤镜和合成类库.下面开始演示关键代码,您也可以在文末下载全部源码: 设置授权 第 ...

  4. $(...).wordExport is not a function

     参考网址:https://laod.cn/code-audit/jquery-is-not-a-function.html 问题描述: 1.view页面引用的是jquery-1.10.2.min.j ...

  5. CSP J/S 2019受虐记

    一枚蒟蒻的游记~ 提高组DAY1 不是说每场考试都有一道签到题吗 那我tm读了三遍题硬是没找到一道水题是怎么回事(是我太弱了吗) 没办法,硬着头皮做T1 暴力写法...期望得分30pts 于是...在 ...

  6. 基于windows平台搭建elasticsearch 补充

    https://www.cnblogs.com/skychen1218/p/8108860.html 参考此大神写的内容,感谢感谢. 不过 好像漏掉了一块内容. 导致出现问题 连接不上的问题.后来修改 ...

  7. Matlab模板模式

    在模板模式(Template Pattern)中,一个抽象类公开定义了执行它的方法的方式/模板.它的子类可以按需要重写方法实现,但调用将以抽象类中定义的方式进行.本文以数据库SQL语法为例来阐述模板模 ...

  8. JS实现重载

    在js中,我们实现重载常用的方式有: 1.根据传入参数的类型执行不同的操作. 2.利用参数中特殊的参数值进行不同的操作. 3.根据参数的个数进行重载. 这里对第三种重载方式的实现进行说明. 实现第三种 ...

  9. 英语dyamaund钻石

    dyamaund  英文词汇,中文翻译为金刚石的;镶钻;用钻石装饰 中文名:镶钻;钻石装饰 外文名:dyamaund 目录 释义 dyamaund 读音:[ˈdaɪəmənd, ˈdaɪmənd] ...

  10. Jmeter学习笔记(二十三)——生成HTML性能报告

    有时候我们写性能报告的时候需要一些性能分布图,JMeter是可以生成HTML性能报告的.这篇博客,简单介绍下在利用jmeter进行性能测试时,是如何生成HTML的可视化测试报告的 一.准备工作 1:j ...