当前位置:网站首页>A. Odd Selection【BruteForce】
A. Odd Selection【BruteForce】
2022-07-03 17:48:00 【Codiplay】
题意
给定n和x(x <= n) 。对于n个数选出x个数,使选出来的数的sum之和为奇数。
错因
偶数一个没有,要求选择出来偶数个,应该输出no。分类讨论少讨论。
分析
对于这个题,我能知道的是起关键作用的是奇数,奇数的个数必须是奇数!其实可以直接根据这个特性枚举了。
但我想分类,想一步直接得到答案,这个讨论的地方既容易错又费脑力,所以直接按照特点进行枚举即可。
所有的brute force错的题都是分类讨论出现漏洞。
首先根据数据范围和题感,判断是brute force的题目!
所以对于数据范围能brute force的题,第一时间不应该是去分类讨论直接得到答案,而是找枚举的对象。
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int main(){
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int t;
cin >> t;
while(t -- ) {
int n, x;
cin >> n >> x;
std::vector<int> a(n);
int cnt[2] = {0, 0};
for (int i = 0; i < n; i ++ ) {
cin >> a[i];
cnt[0] += a[i] & 1;
cnt[1] += !(a[i] & 1);
}
bool ok = false;
for (int i = 1; i <= cnt[0] && i <= x; i += 2)
{
int need = x - i;
if(cnt[1] >= need) ok = true;
}
cout << (ok ? "Yes" : "No") << '\n';
}
return 0;
}
边栏推荐
- [combinatorics] generating function (summation property)
- [RT thread] NXP rt10xx device driver framework -- RTC construction and use
- Baiwen.com 7 days Internet of things smart home learning experience punch in the next day
- [combinatorics] recursive equation (four cases where the non-homogeneous part of a linear non-homogeneous recursive equation with constant coefficients is the general solution of the combination of po
- PUT vs. POST for Uploading Files - RESTful API to be Built Using Zend Framework
- OpenSSL的SSL/BIO_get_fd
- [RT thread] NXP rt10xx device driver framework -- Audio construction and use
- Kubernetes resource object introduction and common commands (III)
- [RT thread] construction and use of --hwtimer of NXP rt10xx device driver framework
- UE4 official charging resources, with a total price of several thousand
猜你喜欢
基于人脸识别的课堂考勤系统 tkinter+openpyxl+face_recognition
QT adjust win screen brightness and sound size
Kubernetes resource object introduction and common commands (III)
TensorBoard快速入门(Pytorch使用TensorBoard)
Baiwen.com 7 days Internet of things smart home learning experience punch in the next day
Analysis report on production and marketing demand and investment forecast of China's PVC industry from 2021 to 2026
Leetcode 108 converts an ordered array into a binary search tree -- recursive method
PS screen printing brush 131, many illustrators have followed suit
Kubernetes resource object introduction and common commands (4)
鸿蒙第四次培训
随机推荐
Servlet specification Part II
Play with fancy special effects. This AE super kit is for you
Analyse ArrayList 3: suppression d'éléments
Brief introduction to the core functions of automatic penetration testing tool
[RT thread] NXP rt10xx device driver framework -- pin construction and use
ArrayList分析3 : 删除元素
PHP returns 500 errors but no error log - PHP return 500 error but no error log
Inheritance of ES6 class
Discussion sur la logique de conception et de mise en oeuvre du processus de paiement
TCP congestion control details | 3 design space
1146_ SiCp learning notes_ exponentiation
How to purchase Google colab members in China
Ml (machine learning) softmax function to realize the classification of simple movie categories
Records of long objects and long judgments in the stream of list
鸿蒙第三次培训
PHP processing - watermark images (text, etc.)
c# . Net tool ecosystem
i++与++i的区别:通俗易懂的讲述他们的区别
互联网医院HIS管理平台源码,在线问诊,预约挂号 智慧医院小程序源码
[combinatorics] recursive equation (summary of the solution process of recursive equation | homogeneous | double root | non-homogeneous | characteristic root is 1 | exponential form | the bottom is th