#include #include using namespace std;

int main() { int t; cin >> t; while (t--) { int n; cin >> n; vector nums(n); int sum = 0; for (int i = 0; i < n; i++) { cin >> nums[i]; sum += nums[i]; } if (sum % 2 == 1) { cout << '0' << endl; // 和为奇数,无法得到开心的数 continue; } int cnt = 0; bool found = false; while (!found) { found = true; for (int i = 0; i < n; i++) { if (nums[i] % 2 == 1) { // 如果当前数是奇数,不能继续除以2了,直接退出循环 found = false; break; } nums[i] /= 2; } if (found) cnt++; } cout << cnt << endl; } return 0; }

C++ 数组操作: 最少除2次数,求和为偶数的数组

原文地址: https://www.cveoy.top/t/topic/orey 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录