当前位置:网站首页>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;
}边栏推荐
- Global and Chinese health care OEM and ODM market status survey and investment planning recommendations report 2022-2028
- Golang unit test, mock test and benchmark test
- Cloud primordial weekly | CNCF released the 2021 cloud primordial development status report, which was released on istio 1.13
- Comparison of kotlin collaboration + retro build network request schemes
- Micro service component sentinel console call
- [combinatorics] recursive equation (the non-homogeneous part is an exponential function and the bottom is the characteristic root | example of finding a special solution)
- PR second time
- Website with JS doesn't work in IE9 until the Developer Tools is activated
- Tensorboard quick start (pytoch uses tensorboard)
- [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
猜你喜欢

Interviewer: why is the value nil not equal to nil?

Research on Swift

1147_ Makefile learning_ Target files and dependent files in makefile

The third day of writing C language by Yabo people

PHP MySQL create database

Analysis report on production and marketing demand and investment forecast of China's PVC industry from 2021 to 2026

Draw some simple graphics with MFC

Records of long objects and long judgments in the stream of list

Implementation of Tetris in C language

(8) HS corner detection
随机推荐
AcWing 3438. 数制转换
PHP MySQL create database
Interviewer: why is the value nil not equal to nil?
MinGW compile boost library
Stm32h7 Hal library SPI DMA transmission has been in busy solution
Talk about the design and implementation logic of payment process
Investigation on the operation prospect of the global and Chinese Anti enkephalinase market and analysis report on the investment strategy of the 14th five year plan 2022-2028
IntelliJ 2021.3 short command line when running applications
自动渗透测试工具核心功能简述
1164 Good in C
How to install PHP on Ubuntu 20.04
Applet with multiple tabs and Swipers + paging of each tab
How to purchase Google colab members in China
Comparison of kotlin collaboration + retro build network request schemes
(8) HS corner detection
Write a program to process a list container of string type. Find a special value in the container 9.27: and delete it if found. Rewrite the above procedure with deque container.
The difference between i++ and ++i: tell their differences easily
Baiwen.com 7 days Internet of things smart home learning experience punch in the next day
Loop through JSON object list
Ssl/bio of OpenSSL_ get_ fd