当前位置:网站首页>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;
}
边栏推荐
- MinGW compile boost library
- [教程]在 CoreOS 上构建你的第一个应用
- Automata and automatic line of non-standard design
- How to purchase Google colab members in China
- [combinatorics] generating function (shift property)
- List的stream中Long对象与long判等问题记录
- The gbase 8A database does not support the DB2 function value (column_name, 0) cluster syntax
- Inheritance of ES6 class
- MySQL grouping query
- [combinatorics] generating function (summation property)
猜你喜欢
[RT thread] NXP rt10xx device driver framework -- RTC construction and use
Hongmeng third training
Micro service component sentinel console call
聊聊支付流程的设计与实现逻辑
IntelliJ 2021.3 short command line when running applications
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
Research on Swift
[combinatorics] generating function (summation property)
Classroom attendance system based on face recognition tkinter+openpyxl+face_ recognition
UE4 official charging resources, with a total price of several thousand
随机推荐
Remote office tools sharing | community essay solicitation
Interviewer: why is the value nil not equal to nil?
Stm32h7 Hal library SPI DMA transmission has been in busy solution
ArrayList分析3 : 删除元素
Comparison of kotlin collaboration + retro build network request schemes
vs2013已阻止安装程序,需安装IE10
Five problems of database operation in commodity supermarket system
Fedora 21 安装 LAMP 主机服务器
互聯網醫院HIS管理平臺源碼,在線問診,預約掛號 智慧醫院小程序源碼
Vs2013 has blocked the installer, and ie10 needs to be installed
Leetcode Valentine's Day Special - looking for a single dog
[Yu Yue education] family education SPOC class 2 reference materials of Shanghai Normal University
Web-ui automated testing - the most complete element positioning method
自动渗透测试工具核心功能简述
AcWing 3438. 数制转换
MySQL grouping query
Leetcode 108 converts an ordered array into a binary search tree -- recursive method
Qt调节Win屏幕亮度和声音大小
Deops入门
ArrayList analysis 3: delete elements