当前位置:网站首页>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;
}边栏推荐
- Applet setting multi account debugging
- 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.
- ES6类的继承
- Where is the monitoring page of RDS database?
- c# .net 工具生态
- [RT thread] NXP rt10xx device driver framework -- RTC construction and use
- Talk about the design and implementation logic of payment process
- Life perception 1
- TCP congestion control details | 3 design space
- [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
猜你喜欢

Micro service component sentinel console call

As soon as we enter "remote", we will never regret, and several people will be happy and several people will be sad| Community essay solicitation

Introduction to SolidWorks gear design software tool geartrax

STM32实现74HC595控制

1147_ Makefile learning_ Target files and dependent files in makefile

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

微服务组件Sentinel控制台调用

Research Report on competitive strategy Outlook Analysis and investment strategic planning of China's smart home equipment industry, 2022-2028

Kubernetes resource object introduction and common commands (III)

Global and Chinese pediatric palliative care drug market development research and investment planning recommendations report 2022-2028
随机推荐
Classroom attendance system based on face recognition tkinter+openpyxl+face_ recognition
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
小程序 多tab 多swiper + 每个tab分页
Enterprise custom form engine solution (XI) -- form rule engine 1
Swm32 series Tutorial 4 port mapping and serial port application
Talk about the design and implementation logic of payment process
Cloud primordial weekly | CNCF released the 2021 cloud primordial development status report, which was released on istio 1.13
QT学习日记9——对话框
AcWing 3438. 数制转换
Web-ui automated testing - the most complete element positioning method
Golang unit test, mock test and benchmark test
i++与++i的区别:通俗易懂的讲述他们的区别
AcWing 4489. Longest subsequence
Kubernetes resource object introduction and common commands (III)
What is the difference between cloud server and cloud virtual machine
互联网医院HIS管理平台源码,在线问诊,预约挂号 智慧医院小程序源码
[combinatorics] recursive equation (special solution form | special solution solving method | special solution example)
SQL injection database operation foundation
Type conversion, variable
supervisor监控Gearman任务