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. Scrum Framework, Process and Story Point

    Scrum Framework Roles Ceremonies Artifacts Scrum Master Sprint Planning Product Backlog Product Owne ...

  2. Shell—详解$0、$1、$2、$#、$*、$@、$?、$$变量

    预定义变量:常用来获取命令行的输入 变量 作用 $0 当前Shell脚本本身的文件名称 $1 脚本接收的第一个参数($1-$9:第1-9个命令行参数名) $2 脚本接收的第二个参数($1-$9:第1- ...

  3. Excel上下标如何设置?

    Excel表格怎么设置上下标?Excel上下标设置技巧 在21世纪的我们,平时的工作和学习中,经常会使用到一些专业的文档,比如方程式.数据的公式和科学计数等,其中均会涉及到许多的上下标符号输入以及使用 ...

  4. Paint.NET软件分享

    date: 2019-07-26 下载链接 官网链接 这是一款类Photoshop的轻量级图片编辑软件,仅有8.7MB.不多说话,直接上链接. 百度网盘链接 提取码:v4b2 软件简介 (百度百科警告 ...

  5. 09. Go 语言并发

    Go 语言并发 并发指在同一时间内可以执行多个任务.并发编程含义比较广泛,包含多线程编程.多进程编程及分布式程序等.本章讲解的并发含义属于多线程编程. Go 语言通过编译器运行时(runtime),从 ...

  6. [译]Vulkan教程(02)概况

    [译]Vulkan教程(02)概况 这是我翻译(https://vulkan-tutorial.com)上的Vulkan教程的第2篇. This chapter will start off with ...

  7. PAT 1005 Spell It Right 字符串处理

    Given a non-negative integer N, your task is to compute the sum of all the digits of N, and output e ...

  8. mybatis的mapper.xml中使用java类中的全局变量

    select * from demo where status = '${@cn.jichi.Global@zz}'

  9. ASP.NET Core Web 应用程序系列(三)- 在ASP.NET Core中使用Autofac替换自带DI进行构造函数和属性的批量依赖注入(MVC当中应用)

    在上一章中主要和大家分享了在ASP.NET Core中如何使用Autofac替换自带DI进行构造函数的批量依赖注入,本章将和大家继续分享如何使之能够同时支持属性的批量依赖注入. 约定: 1.仓储层接口 ...

  10. Python的6种内建序列之通用操作

    数据结构式通过某种方式(例如对元素进行编号)组织在一起的数据元素的集合,这些数据元素可以是数字或者字符,甚至可以是其他数据结构.在Python中,最基本的数据结构是序列(sequence).序列中的每 ...