当前位置:网站首页>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;
}边栏推荐
- Complex convolutional neural network: cv-cnn
- MySQL development specification pdf
- SSL v** technical principle
- Google software version experience cycle
- 等保测评结论为差,是不是表示等保工作白做了?
- el-table-column行按钮防重控制loading
- LeetCode-470-用Rand7()实现Rand10()
- 【crossbeam系列】5 crossbeam-util和crossbeam-queue:一些实用的小东西
- 瓜分1000+万奖金池,昇腾AI创新大赛2022实力赋能开发者
- pwm转0-5V/0-10V/1-5V线性信号变送器
猜你喜欢

#夏日挑战赛# HarmonyOS - 方舟开发框架ArkUI 流光按钮效果

GWD:基于高斯Wasserstein距离的旋转目标检测 | ICML 2021

When easygbs calls the interface for obtaining real-time snapshots, how to solve the problem of white squares?

【云原生】Nacos-TaskManager 任务管理的使用

Stlink troubleshooting

Three development trends of enterprise application viewed from the third technological revolution

动作捕捉系统用于苹果采摘机器人

《网络是怎么样连接的》读书笔记 - 服务器端的局域网中(四)

企业转型升级之道:数字化转型,思想先行

硬件开发笔记(八): 硬件开发基本流程,制作一个USB转RS232的模块(七):创建基础DIP元器件(晶振)封装并关联原理图元器件
随机推荐
华为云AOM 2.0版本发布
Deeply understand promise's hand and teach you to write a version
C语言大作业——匹配系统
火山引擎入选国内首个《边缘计算产业全景图》
瓜分1000+万奖金池,昇腾AI创新大赛2022实力赋能开发者
Kotlin annotation Statement and use
postgresql源码学习(24)—— 事务日志⑤-日志写入WAL Buffer
企业转型升级之道:数字化转型,思想先行
防范企业数据泄露,就用网络安全产品堡垒机!
Summary of recent work
Excel中构建SQL语句
Alibaba cloud experience Award: use polardb-x and Flink to build a large real-time data screen
MySQL development specification pdf
PostgreSQL source code learning (25) -- transaction log ⑥ - wait for log writing to complete
11. application layer data transmission format / port number -bite
2022 OpenVINO DevCon 大揭秘!英特尔携众多合作伙伴深化开发者生态建设,释放AI产业创新潜能
【云原生】Nacos-TaskManager 任务管理的使用
C#学习一:值类型与引用类型
PostgreSQL source code learning (24) -- transaction log ⑤ - log writing to wal buffer
Flink SQL task taskmanager memory settings