time limit per test3 seconds
memory limit per test256 megabytes
input: standard input
output: standard output

There are n positive integers a1,a2,…,an. For the one move you can choose any even value c and divide by two all elements that equal c.
For example, if a=[6,8,12,6,3,12] and you choose c=6, and a is transformed into a=[3,8,12,3,3,12] after the move.
You need to find the minimal number of moves for transforming a to an array of only odd integers (each element shouldn’t be divisible by 2).

Input
The first line of the input contains one integer t(1≤t≤104) — the number of test cases in the input. Then t test cases follow.
The first line of a test case contains n(1≤n≤2⋅105) — the number of integers in the sequence a. The second line contains positive integers a1,a2,…,an(1≤ai≤109).The sum of n for all test cases in the input doesn’t exceed 2⋅105.
Output
For t 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 2).

Example
Input
4
6
40 6 40 3 20 1
1
1024
4
2 4 8 16
3
3 1 7
Output
4
10
4
0

题意:
t组数,每组n个数,每一次操作可以把数组里相同的同时除以2,直到数组里所有的数都变成了奇数
只要用一个数组把每一个偶数的变化过程标记下来,如果循环到某一个数字时当前数字已经被标记就结束当前循环,然后记录一共除了多少次就好。介于数字过大,不用定义一个int数组,所以用map就好了(不过这么简单的题目 emmm 应该不会有人查博客吧)
记录这题是因为这个做法让我想起了以前cc哥哥出过的一道题,想让我们在本地跑5分钟才能得出答案,但因为用了这个做法就得以快速ac。那道题找不到了,就用这道题来代替下,让自己有一个印象~
还是贴一个代码叭:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int t,n;
ll times; int cmp(int a,int b){
return a>b;
} int main(){
cin>>t;
while(t--){
cin>>n;
times = 0;
for(int i=1;i<=n;i++){
cin>>a[i];
}
sort(a+1,a+1+n,cmp);
map<int,int> mp;
for(int i=1;i<=n;i++){
if(a[i]%2==1){
continue;
}else{
while(a[i]%2==0 && mp[a[i]]==0){
mp[a[i]]=1;
a[i]/=2;
times++;
}
}
}
cout<<times<<endl;
}
return 0; }

  

————————————————
CSDN链接:https://blog.csdn.net/weixin_43880627/article/details/103622672

Make Them Odd的更多相关文章

  1. [LeetCode] Odd Even Linked List 奇偶链表

    Given a singly linked list, group all odd nodes together followed by the even nodes. Please note her ...

  2. Odd Even Linked List

    Given a singly linked list, group all odd nodes together followed by the even nodes. Please note her ...

  3. LeetCode 328. Odd Even Linked List

    Given a singly linked list, group all odd nodes together followed by the even nodes. Please note her ...

  4. tr:even 与tr:odd

    :even匹配所有索引值为偶数的元素,从 0 开始计数查找表格的1.3.5...行(即索引值0.2.4...)<table> <tr><td>Header 1< ...

  5. Leetcode Odd Even Linked List

    Given a singly linked list, group all odd nodes together followed by the even nodes. Please note her ...

  6. CSS3伪类选择器:nth-child()(nth-child(odd)/nth-child(even))

    nth-child(odd):奇数 nth-child(even):偶数 使用时,如果是精确到数字时,切记是从同一级别的元素开始计算,而不是指定某个类才开始计算. 比如: <li>< ...

  7. [CareerCup] 5.6 Swap Odd and Even Bits 交换奇偶位

    5.6 Write a program to swap odd and even bits in an integer with as few instructions as possible (e. ...

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

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

  9. 328. Odd Even Linked List——多利用fake_head

    Given a singly linked list, group all odd nodes together followed by the even nodes. Please note her ...

  10. 越狱Season 1-Episode 12:Odd Man Out

    Season 1-Episode 12:Odd Man Out -Sorry to keep you waiting. 抱歉让你等了半天 -Oh, it's, uh, not a problem. 嗯 ...

随机推荐

  1. How to: Use Both Entity Framework and XPO in a Single Application 如何:在单个应用程序中同时使用实体框架和 XPO

    This topic demonstrates how to create a simple XAF application that uses both the Entity Framework ( ...

  2. seaborn画出的一些好看的图片

    PYSPARK_DRIVER_PYTHON=/home/zhangyu/anaconda3/bin/jupyter-notebook PYSPARK_DRIVER_PYTHON_OPTS=" ...

  3. swiper 轮播中常用的效果,持续更新

    swiper一款非常好用的轮播插件,支持移动端和PC端,用过很多次了,这次简单的总结一下.方便以后查找使用,说明一下,下面的例子是基于swiper 4.0+版本的,如果你是其他的版本,请自行前往官网查 ...

  4. QT--图灵机器人

    QT--图灵机器人 1.登陆图灵机器人官网注册一个图灵机器人 2.获取apikey 3.pro文件添加 QT       += core gui network 4.头文件 #include < ...

  5. SQL Server解惑——为什么你的查询结果超出了查询时间范围

    废话少说,直接上SQL代码(有兴趣的测试验证一下),下面这个查询语句为什么将2008-11-27的记录查询出来了呢?这个是同事遇到的一个问题,个人设计了一个例子. USE AdventureWorks ...

  6. Office2019新增哪些功能

    上一篇文章我们知道了office为什么没有2017/2018版本,那个是因为微软office是时隔三年一更新的软件,这不office2019就出来了.一款软件,只有不断的完善自身功能,进行不断的更新, ...

  7. JavaScript-----9.函数

    1.函数的使用 1.1 声明函数和调用函数 //1.声明函数 //function 函数名() { // //函数体 //} function sayHi() { console.log('hi~') ...

  8. Web安全测试学习笔记-DVWA-图片上传

    很多网站都有上传资源(图片或者文件)的功能,资源上传后一般会存储在服务器的一个文件夹里面,如果攻击者绕过了上传时候的文件类型验证,传了木马或者其他可执行的代码上去,那服务器就危险了. 我用DVWA的文 ...

  9. 工作笔记 之 Python应用技术

    python socket编程详细介绍 网络上的两个程序通过一个双向的通信连接实现数据的交换,这个连接的一端称为一个socket,建立网络通信连接至少要一对端口号(socket). Socket本质是 ...

  10. Response to 16岁的篮球投手

    关于篮球,我想写的很多,被偏爱的运动,被赞美的运动,带着青春的万丈光泽. 我们对易建联的苛刻是因为想当然,对大侄子的溺爱是因为急功近利.过于娱乐化和商业化,让一项竞技体育变得像是豆瓣八组的吃瓜盛宴. ...