[codeforces 1277B] Make Them Odd 模拟
总目录详见https://blog.csdn.net/mrcrack/article/details/103564004
在线测评地址http://codeforces.com/contest/1277/problem/B
Problem | Lang | Verdict | Time | Memory |
---|---|---|---|---|
B - Make Them Odd | GNU C++11 | Accepted | 78 ms | 3000 KB |
#include <cstdio>
#include <algorithm>
#define maxn 200010
using namespace std;
struct node{
int v,num;
}a[maxn],b[maxn];
int cmp(node a,node b){
return a.v==b.v?a.num>b.num:a.v<b.v;
}
int main(){
int t,n,i,cnt,ans;
scanf("%d",&t);
while(t--){
ans=0;
scanf("%d",&n);
for(i=1;i<=n;i++)scanf("%d",&a[i].v),a[i].num=0;
for(i=1;i<=n;i++)
while(a[i].v%2==0)a[i].v/=2,a[i].num++;
sort(a+1,a+1+n,cmp);
b[1]=a[1],cnt=1;
for(i=2;i<=n;i++)
if(a[i].v!=a[i-1].v)b[++cnt]=a[i];
for(i=1;i<=cnt;i++)ans+=b[i].num;
printf("%d\n",ans);
}
return 0;
}