当前位置:网站首页>A. Beat The Odds
A. Beat The Odds
2022-06-29 21:35:00 【Felven】
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Given a sequence a1,a2,…,ana1,a2,…,an, find the minimum number of elements to remove from the sequence such that after the removal, the sum of every 22 consecutive elements is even.
Input
Each test contains multiple test cases. The first line contains a single integer tt (1≤t≤1001≤t≤100) — the number of test cases. Description of the test cases follows.
The first line of each test case contains a single integer nn (3≤n≤1053≤n≤105).
The second line of each test case contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤1091≤ai≤109) — elements of the sequence.
It is guaranteed that the sum of nn over all test cases does not exceed 105105.
Output
For each test case, print a single integer — the minimum number of elements to remove from the sequence such that the sum of every 22 consecutive elements is even.
Example
input
Copy
2 5 2 4 3 6 8 6 3 5 9 7 1 3
output
Copy
1 0
Note
In the first test case, after removing 33, the sequence becomes [2,4,6,8][2,4,6,8]. The pairs of consecutive elements are {[2,4],[4,6],[6,8]}{[2,4],[4,6],[6,8]}. Each consecutive pair has an even sum now. Hence, we only need to remove 11 element to satisfy the condition asked.
In the second test case, each consecutive pair already has an even sum so we need not remove any element.
Problem solving instructions : Water problem , Or delete all the odd numbers 、 Or delete all even numbers .
#include"stdio.h"
#include"math.h"
int main()
{
int k, b, x;
scanf("%d", &k);
for (int i = 0; i<k; i++)
{
int br = 0;
scanf("%d", &b);
for (int j = 0; j<b; j++)
{
scanf("%d", &x);
if (x % 2 != 0)
{
br++;
}
}
if (br > b - br)
{
printf("%d\n", b - br);
}
else
{
printf("%d\n", br);
}
}
return 0;
}
边栏推荐
- Live broadcast preview | PostgreSQL kernel Interpretation Series Lecture 1: overview of PostgreSQL system
- Reinforcement learning weekly (issue 51): integration of PAC, ilql, RRL & model free reinforcement learning into micro grid control: overview and Enlightenment
- Redis (I) -- getting started with redis (1) -- redis introduction, installation and startup, and common configurations
- Matlab output format control%d,%f,%c,%s usage
- Report delivery engineer
- 分析影响导电滑环传输信号的因素
- THREEJS基础入门
- Top ten questions for senior Performance Test Engineer
- [advanced ROS] Lecture 3 ROS file system and distributed communication
- Viewing technological changes through Huawei Corps (V): smart Park
猜你喜欢
Selection of materials for space conductive disc slip ring
时钟树综合(CTS)
Explain PBR texture maps
Navigation exercises [microcomputer principles] [exercises]
Layer 3 loop brought by route Summary - solution experiment
习近平在湖北武汉考察时强调 把科技的命脉牢牢掌握在自己手中 不断提升我国发展独立性自主性安全性
Sophon CE community edition goes online, and free get is a lightweight, easy-to-use, efficient and intelligent data analysis tool
阿里云发布《中国机器人产业图谱(2022)》,122页pdf
What is a SYN Flood attack? How to protect?
计算成像前沿进展
随机推荐
唯品会关键词搜索API接口(item_search-按关键字搜索唯品会商品API接口),唯品会API接口
时钟树综合(CTS)
什么是 SYN 洪水攻击?如何防护?
阿里巴巴商品详情API接口(item_get-获得商品详情接口),阿里巴巴API接口
一颗新的北极星已经升起!
GoAhead 翻译—Active Server Pages
leetcode:238. 除自身以外数组的乘积
Matlab adds noise / disturbance to data
Win10添加ssh公钥
Design of VHDL telephone billing system
TMUX settings
HAproxy + Keepalive实现LDAP代理服务
My creation anniversary
企业实施MES系统的关键点详解
利用积分商城游戏进行营销需要避免哪些问题出现?
String类的常用方法
Analysis on the true topic of "cost management" by Guangdong second-class cost engineer
leetcode:238. Product of arrays other than itself
MES系统与ERP如何集成?本文告诉你答案