当前位置:网站首页>A. Beat The Odds
A. Beat The Odds
2022-06-29 15:36: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.
解题说明:水题,要么删除其中所有的奇数、要么删除其中所有的偶数。
#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;
}边栏推荐
- mysql XA 分布式事务
- Symfony framework security component firewall configuration
- 火山引擎入选国内首个《边缘计算产业全景图》
- Deeply understand promise's hand and teach you to write a version
- 小程序判断数据为不为空
- Leetcode notes: Weekly contest 299
- three. JS and Gaode map are combined to introduce obj format model - effect demonstration
- Taro 小程序开启wxml代码压缩
- MySQL XA distributed transaction
- 华为云AOM 2.0版本发布
猜你喜欢
随机推荐
Andorid Jetpack Hilt
"Game engine shallow in shallow out" 98 Substancepainer plug-in development
Deeply understand promise's hand and teach you to write a version
swift JSONSerialization
three. JS and Gaode map are combined to introduce obj format model - effect demonstration
CVPR 2022 | 大幅减少零样本学习所需的人工标注,马普所和北邮提出富含视觉信息的类别语义嵌入
swoole TCP 分布式实现
What are the advantages of intelligent chat robots? Senior independent station sellers tell you!
从第三次技术革命看企业应用三大开发趋势
#夏日挑战赛# HarmonyOS - 方舟开发框架ArkUI 流光按钮效果
Google software version experience cycle
Leetcode notes: Weekly contest 299
Introduction to radar related contents
Dynamically listening for DOM element height changes
wallys/m.2/Adapter card(one pcie1x to 4 x Mini PCIE)
EasyGBS调用获取实时快照接口时,出现白色方块该如何解决?
如何使用SMS向客户传递服务信息?指南在这里!
墨天轮“高可用架构”干货文档分享(含Oracle、MySQL、PG资料124篇)
Volcano engine was selected into the first "panorama of edge computing industry" in China
postgresql源码学习(24)—— 事务日志⑤-日志写入WAL Buffer









