D - Make Them Odd CodeForces - 1277B
思路
-
思路:用 map<int, int> 来存 1~1e9的数据,对于同一个数字我们只存入到 map中一次这样节省时间,在存到时候 在选择树的时候从map 中的大大数字往小的数字开始除,在除2之后又产生了新的没出现过的数字,把这个数字添加的map 中去。。
-
另外在往 map 存数的时候,由于map默认是从按key 小到大排序的,这一题由于大数的正负对 结果没有影响,这样我们把 某个数的 负数存到map中这样,就能得到 从大到小排序了
代码
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<map>
#include<vector>
#include<queue>
#include<stack>
void fre() { freopen("A.txt","r",stdin); freopen("Ans.txt","w",stdout); }
using namespace std;
const int mxn = 1e5 + 10;
map<int, int> mp;
int main()
{
/* fre(); */
int t;
scanf("%d", &t);
while(t --)
{
mp.clear();
int n;
scanf("%d", &n);
int x;
for(int i = 0; i < n; i ++)
{
scanf("%d", &x);
if(x % 2 == 0 &&! mp[-x])
mp[-x] = 1;
}
int cnt = 0;
for(auto x : mp)
{
cnt ++;
int val = x.first;
val /= 2;
if(val % 2 == 0 && ! mp[val])
mp[val] = 1;
}
printf("%d\n", cnt);
}
return 0;
}