当前位置:网站首页>A. Odd Selection【BruteForce】
A. Odd Selection【BruteForce】
2022-07-03 17:53:00 【Codiplay】
The question
Given n and x(x <= n) . about n Select the number x Number , Make the selected number sum The sum is odd .
Cause of error
Even one does not , It is required to select an even number , The output should be no. Less discussion on classification .
analysis
For this question , What I can know is that odd numbers play a key role , The number of odd numbers must be odd ! In fact, you can enumerate directly according to this feature .
But I want to classify , Want to get the answer directly in one step , This discussion is easy to make mistakes and takes a lot of brains , So you can enumerate directly according to the characteristics .
be-all brute force The wrong questions are the loopholes in the classified discussion .
First, according to the range of data and the sense of problem , Judgment is brute force The subject of !
So the data range can brute force The topic , The first time should not be to discuss the classification and get the answer directly , Instead, look for enumerated objects .
#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;
}
边栏推荐
- PHP processing - watermark images (text, etc.)
- SQL injection database operation foundation
- Global and Chinese pediatric palliative care drug market development research and investment planning recommendations report 2022-2028
- The gbase 8A database does not support the DB2 function value (column_name, 0) cluster syntax
- 1147_ Makefile learning_ Target files and dependent files in makefile
- Classroom attendance system based on face recognition tkinter+openpyxl+face_ recognition
- PR second time
- Codeforces Round #803 (Div. 2) C. 3SUM Closure
- Stm32h7 Hal library SPI DMA transmission has been in busy solution
- Kotlin's collaboration: Context
猜你喜欢
Vs2013 has blocked the installer, and ie10 needs to be installed
PHP MySQL create database
vs2013已阻止安装程序,需安装IE10
List的stream中Long对象与long判等问题记录
微服务组件Sentinel控制台调用
IntelliJ 2021.3 short command line when running applications
[set theory] order relation: summary (partial order relation | partial order set | comparable | strictly less than | covering | hasto | total order relation | quasi order relation | partial order rela
一入“远程”终不悔,几人欢喜几人愁。| 社区征文
模块九作业
Micro service component sentinel console call
随机推荐
毕业总结
Classroom attendance system based on face recognition tkinter+openpyxl+face_ recognition
Analyse ArrayList 3: suppression d'éléments
Leetcode 108 converts an ordered array into a binary search tree -- recursive method
Brief introduction to the core functions of automatic penetration testing tool
Create a new file from templates with bash script - create new file from templates with bash script
PHP MySQL inserts multiple pieces of data
Deops入门
[Yu Yue education] family education SPOC class 2 reference materials of Shanghai Normal University
PUT vs. POST for Uploading Files - RESTful API to be Built Using Zend Framework
Y is always discrete and can't understand, how to solve it? Answer: read it several times
Managing multiple selections with MVVM - managing multiple selections with MVVM
Discussion sur la logique de conception et de mise en oeuvre du processus de paiement
Type conversion, variable
PHP returns 500 errors but no error log - PHP return 500 error but no error log
Postfix tips and troubleshooting commands
How to read the source code [debug and observe the source code]
Research on Swift
微服务组件Sentinel控制台调用
[mathematical logic] equivalent calculus and reasoning calculus of predicate logic (individual word | predicate | quantifier | predicate logic formula | two basic formulas | proposition symbolization