当前位置:网站首页>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;
}边栏推荐
- Fedora 21 installs lamp host server
- win32:堆破坏的dump文件分析
- The gbase 8A database does not support the DB2 function value (column_name, 0) cluster syntax
- PHP returns 500 errors but no error log - PHP return 500 error but no error log
- Enterprise custom form engine solution (XI) -- form rule engine 1
- Automata and automatic line of non-standard design
- 数学公式(测试)
- The third day of writing C language by Yabo people
- Create a new file from templates with bash script - create new file from templates with bash script
- Classroom attendance system based on face recognition tkinter+openpyxl+face_ recognition
猜你喜欢

面试官:值为 nil 为什么不等于 nil ?

Five problems of database operation in commodity supermarket system

STM32实现74HC595控制

PHP MySQL create database

1164 Good in C

Redis core technology and practice - learning notes (VI) how to achieve data consistency between master and slave Libraries

Internet Hospital his Management Platform source, online Inquiry, appointment Registration Smart Hospital Small program source

Vs2013 has blocked the installer, and ie10 needs to be installed
![[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](/img/f1/c96c4a6d34e1ae971f492f4aed5a93.jpg)
[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

How to deploy applications on kubernetes cluster
随机推荐
Deops入门
(9) Opencv Canny edge detection
Tensorboard quick start (pytoch uses tensorboard)
Hongmeng third training
Distributed task distribution framework gearman
互联网医院HIS管理平台源码,在线问诊,预约挂号 智慧医院小程序源码
OpenSSL的SSL/BIO_get_fd
The difference between i++ and ++i: tell their differences easily
Research Report on investment trends and development planning of China's thermal insulation material industry, 2022-2028
面试官:值为 nil 为什么不等于 nil ?
Analyse ArrayList 3: suppression d'éléments
AcWing 3438. Number system conversion
c# . Net tool ecosystem
How to read the source code [debug and observe the source code]
Postfix 技巧和故障排除命令
POM in idea XML graying solution
Life perception 1
1146_ SiCp learning notes_ exponentiation
Classroom attendance system based on face recognition tkinter+openpyxl+face_ recognition
Introduction to PHP MySQL